Class: Uur::Entries

Inherits:
Array
  • Object
show all
Defined in:
lib/uur/entries.rb

Instance Method Summary collapse

Instance Method Details

#durationObject



12
13
14
# File 'lib/uur/entries.rb', line 12

def duration
  inject(0) { |total, entry| total + entry.duration }
end

#group_by(&block) ⇒ Object



8
9
10
# File 'lib/uur/entries.rb', line 8

def group_by(&block)
  each_with_object(Hash.new { |hash, key| hash[key] = Entries.new }) { |entry, grouped| grouped[block.call(entry)] << entry }
end

#within(since, to) ⇒ Object



4
5
6
# File 'lib/uur/entries.rb', line 4

def within(since, to)
  self.class.new(select { |entry| (since.nil? || entry.starts_at >= since) && (to.nil? || entry.ends_at <= to) })
end