Class: YinxSt::Batches
- Inherits:
-
Object
- Object
- YinxSt::Batches
- Defined in:
- lib/yinx_st/batches.rb
Instance Attribute Summary collapse
-
#all_notes ⇒ Object
readonly
Returns the value of attribute all_notes.
-
#smallest_batch_size ⇒ Object
readonly
Returns the value of attribute smallest_batch_size.
Instance Method Summary collapse
- #batches_of_each_note ⇒ Object
-
#initialize(n) ⇒ Batches
constructor
A new instance of Batches.
- #latest_id ⇒ Object
- #of_guid(guid) ⇒ Object
- #time_line ⇒ Object
- #unwind_tags ⇒ Object
Constructor Details
#initialize(n) ⇒ Batches
Returns a new instance of Batches.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#all_notes ⇒ Object (readonly)
Returns the value of attribute all_notes
6 7 8 |
# File 'lib/yinx_st/batches.rb', line 6 def all_notes @all_notes end |
#smallest_batch_size ⇒ Object (readonly)
Returns the value of attribute smallest_batch_size
6 7 8 |
# File 'lib/yinx_st/batches.rb', line 6 def smallest_batch_size @smallest_batch_size end |
Instance Method Details
#batches_of_each_note ⇒ Object
27 28 29 30 31 32 33 |
# 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 ⇒ Object
35 36 37 |
# 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) ⇒ Object
23 24 25 |
# File 'lib/yinx_st/batches.rb', line 23 def of_guid guid batches_of_each_note[guid] end |
#time_line ⇒ Object
43 44 45 |
# File 'lib/yinx_st/batches.rb', line 43 def time_line @time_line ||= all_notes.map(&:dump_day).uniq.sort end |
#unwind_tags ⇒ Object
39 40 41 |
# File 'lib/yinx_st/batches.rb', line 39 def @unwind_tags ||= all_notes.map{|note| note.}.flatten end |