class YinxSt::Batches

Attributes

all_notes[R]
smallest_batch_size[R]

Public Class Methods

new(n) click to toggle source
# File lib/yinx_st/batches.rb, line 8
def initialize n
  batches = Yinx::SQL::JsonBatch.last(n)
  @smallest_batch_size = Float::INFINITY
  @all_notes = batches.each_with_object([]) do |b, rs|
    @smallest_batch_size = b.batch.size if b.batch.size < @smallest_batch_size
    b.batch.each_with_object(rs) do |h, rs|
      n = Yinx::NoteMeta.from_h h
      n.dump_id = b.id
      n.dump_at = (b.fixed_dump_date or b.created_at)
      n.batches = self
      rs << n
    end
  end
end

Public Instance Methods

batches_of_each_note() click to toggle source
# File lib/yinx_st/batches.rb, line 27
def batches_of_each_note
  @batches_of_each_note ||= Hash[
    all_notes.
      group_by(&:guid).
      map{|guid, versions| [guid, versions.sort{|v1, v2| v2.dump_id <=> v1.dump_id}]}
  ]
end
latest_id() click to toggle source
# File lib/yinx_st/batches.rb, line 35
def latest_id
  @latest_id ||= @all_notes.max{|n1, n2| n1.dump_id <=> n2.dump_id}.dump_id
end
of_guid(guid) click to toggle source
# File lib/yinx_st/batches.rb, line 23
def of_guid guid
  batches_of_each_note[guid]
end
time_line() click to toggle source
# File lib/yinx_st/batches.rb, line 43
def time_line
  @time_line ||= all_notes.map(&:dump_day).uniq.sort
end
unwind_tags() click to toggle source
# File lib/yinx_st/batches.rb, line 39
def unwind_tags
  @unwind_tags ||= all_notes.map{|note| note.unwind_tags}.flatten
end