Class: StandupMD::EntryList
- Inherits:
-
Object
- Object
- StandupMD::EntryList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/standup_md/entry_list.rb
Overview
Enumerable list of entries.
Instance Method Summary collapse
-
#<<(entry) ⇒ StandupMD::EntryList
Appends entries to list.
-
#filter(start_date, end_date) ⇒ Array
Returns entries that are between the start and end date.
-
#filter!(start_date, end_date) ⇒ StandupMD::EntryList
Replaces entries with results of filter.
-
#find(date) ⇒ StandupMD::Entry
Finds an entry based on date.
-
#initialize(*entries) ⇒ StandupMD::EntryList
constructor
Construct a list.
-
#sort ⇒ StandupMD::EntryList
Returns a copy of self sorted by date.
-
#sort! ⇒ StandupMD::EntryList
Replace entries with sorted entries by date.
-
#sort_reverse ⇒ StandupMD::EntryList
Returns a copy of self sorted by date, reversed.
-
#to_h ⇒ Hash
The list as a hash, with the dates as keys.
Constructor Details
#initialize(*entries) ⇒ StandupMD::EntryList
Construct a list. Can pass any amount of StandupMD::Entry instances.
18 19 20 21 22 |
# File 'lib/standup_md/entry_list.rb', line 18 def initialize(*entries) entries.each { |entry| validate_entry(entry) } @entries = entries end |
Instance Method Details
#<<(entry) ⇒ StandupMD::EntryList
Appends entries to list.
30 31 32 33 34 |
# File 'lib/standup_md/entry_list.rb', line 30 def <<(entry) validate_entry(entry) @entries << entry end |
#filter(start_date, end_date) ⇒ Array
Returns entries that are between the start and end date. This method assumes the list has already been sorted.
81 82 83 84 85 |
# File 'lib/standup_md/entry_list.rb', line 81 def filter(start_date, end_date) self.class.new( *@entries.select { |e| e.date.between?(start_date, end_date) } ) end |
#filter!(start_date, end_date) ⇒ StandupMD::EntryList
Replaces entries with results of filter.
95 96 97 98 |
# File 'lib/standup_md/entry_list.rb', line 95 def filter!(start_date, end_date) @entries = filter(start_date, end_date).to_a self end |
#find(date) ⇒ StandupMD::Entry
Finds an entry based on date. This method assumes the list has already been sorted.
43 44 45 |
# File 'lib/standup_md/entry_list.rb', line 43 def find(date) entries.bsearch { |entry| date <=> entry.date } end |
#sort ⇒ StandupMD::EntryList
Returns a copy of self sorted by date.
51 52 53 |
# File 'lib/standup_md/entry_list.rb', line 51 def sort self.class.new(*@entries.sort) end |
#sort! ⇒ StandupMD::EntryList
Replace entries with sorted entries by date.
59 60 61 62 |
# File 'lib/standup_md/entry_list.rb', line 59 def sort! @entries = @entries.sort self end |
#sort_reverse ⇒ StandupMD::EntryList
Returns a copy of self sorted by date, reversed.
68 69 70 |
# File 'lib/standup_md/entry_list.rb', line 68 def sort_reverse self.class.new(*@entries.sort.reverse) end |
#to_h ⇒ Hash
The list as a hash, with the dates as keys.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/standup_md/entry_list.rb', line 104 def to_h @entries.map do |e| [ e.date, { "current" => e.current, "previous" => e.previous, "impediments" => e.impediments, "notes" => e.notes } ] end.to_h end |