class StandupMD::EntryList
Enumerable list of entries.
Public Class Methods
Source
# File lib/standup_md/entry_list.rb, line 18 def initialize(*entries) entries.each { |entry| validate_entry(entry) } @entries = entries end
Construct a list. Can pass any amount of StandupMD::Entry instances.
@param [Entry] entries
@return [StandupMD::EntryList]
Public Instance Methods
Source
# File lib/standup_md/entry_list.rb, line 30 def <<(entry) validate_entry(entry) @entries << entry end
Appends entries to list.
@param [StandupMD::Entry] entry
@return [StandupMD::EntryList]
Source
# 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
Returns entries that are between the start and end date. This method assumes the list has already been sorted.
@param [Date] start_date
@param [Date] end_date
@return [Array]
Source
# 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
Replaces entries with results of filter.
@param [Date] start_date
@param [Date] end_date
@return [StandupMD::EntryList]
Source
# File lib/standup_md/entry_list.rb, line 43 def find(date) entries.bsearch { |entry| date <=> entry.date } end
Finds an entry based on date. This method assumes the list has already been sorted.
@param [Date] date
@return [StandupMD::Entry]
Source
# File lib/standup_md/entry_list.rb, line 51 def sort self.class.new(*@entries.sort) end
Returns a copy of self sorted by date.
@return [StandupMD::EntryList]
Source
# File lib/standup_md/entry_list.rb, line 59 def sort! @entries = @entries.sort self end
Replace entries with sorted entries by date.
@return [StandupMD::EntryList]
Source
# File lib/standup_md/entry_list.rb, line 68 def sort_reverse self.class.new(*@entries.sort.reverse) end
Returns a copy of self sorted by date, reversed.
@return [StandupMD::EntryList]
Source
# 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
The list as a hash, with the dates as keys.
@return [Hash]
Delegators
Public Instance Methods
Source
# File lib/standup_md/entry_list.rb, line 133 def_delegators :@entries, :each, :empty?, :size, :first, :last
The following are forwarded to @entries, which is the underlying array of entries.
each-
Iterate over each entry.
empty?-
Is the list empty?
size-
How many items are in the list?
first-
The first record in the list.
last-
The last record in the list.