class StandupMD::EntryList
Enumerable list of entries.
Public Class Methods
Access to the class's configuration.
@return [StandupMD::Config::EntryList]
# File lib/standup_md/entry_list.rb, line 14 def self.config @config ||= StandupMD.config.entry_list end
Contruct a list. Can pass any amount of StandupMD::Entry
instances.
@param [Entry] entries
@return [StandupMD::EntryList]
# File lib/standup_md/entry_list.rb, line 24 def initialize(*entries) @config = self.class.config unless entries.all? { |e| e.is_a?(StandupMD::Entry) } raise ArgumentError, 'Entry must instance of StandupMD::Entry' end @entries = entries end
Public Instance Methods
Appends entries to list.
@param [StandupMD::Entry] entry
@return [Array]
# File lib/standup_md/entry_list.rb, line 44 def <<(entry) unless entry.is_a?(StandupMD::Entry) raise ArgumentError, 'Entry must instance of StandupMD::Entry' end @entries << entry end
Iterate over the list and yield each entry.
# File lib/standup_md/entry_list.rb, line 34 def each(&block) @entries.each(&block) end
Is the list empty?
@return [Boolean] true if empty
# File lib/standup_md/entry_list.rb, line 162 def empty? @entries.empty? 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]
# File lib/standup_md/entry_list.rb, line 92 def filter(start_date, end_date) self.class.new( *@entries.select { |e| e.date.between?(start_date, end_date) } ) end
Replaces entries with results of filter.
@param [Date] start_date
@param [Date] end_date
@return [Array]
# File lib/standup_md/entry_list.rb, line 106 def filter!(start_date, end_date) @entries = filter(start_date, end_date) self end
Finds an entry based on date. This method assumes the list has already been sorted.
# File lib/standup_md/entry_list.rb, line 54 def find(key) to_a.bsearch { |e| e.date == key } end
The first entry in the list. This method assumes the list has already been sorted.
@return [StandupMD::Entry]
# File lib/standup_md/entry_list.rb, line 137 def first to_a.first end
The last entry in the list. This method assumes the list has already been sorted.
@return [StandupMD::Entry]
# File lib/standup_md/entry_list.rb, line 146 def last to_a.last end
How many entries are in the list.
@return [Integer]
# File lib/standup_md/entry_list.rb, line 154 def size @entries.size end
Returns a copy of self sorted by date.
@return [StandupMD::EntryList]
# File lib/standup_md/entry_list.rb, line 62 def sort self.class.new(*@entries.sort) end
Replace entries with sorted entries by date.
@return [StandupMD::EntryList]
# File lib/standup_md/entry_list.rb, line 70 def sort! @entries = @entries.sort self end
Returns a copy of self sorted by date.
@return [StandupMD::EntryList]
# File lib/standup_md/entry_list.rb, line 79 def sort_reverse self.class.new(*@entries.sort.reverse) end
The list as a hash, with the dates as keys.
@return [Hash]
# File lib/standup_md/entry_list.rb, line 115 def to_h Hash[@entries.map { |e| [e.date, { 'current' => e.current, 'previous' => e.previous, 'impediments' => e.impediments, 'notes' => e.notes }]}] end
The entry list as a json object.
@return [String]
# File lib/standup_md/entry_list.rb, line 128 def to_json to_h.to_json end