class StandupMD::EntryList

Enumerable list of entries.

Public Class Methods

config() click to toggle source

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
new(*entries) click to toggle source

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

<<(entry) click to toggle source

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
each(&block) click to toggle source

Iterate over the list and yield each entry.

# File lib/standup_md/entry_list.rb, line 34
def each(&block)
  @entries.each(&block)
end
empty?() click to toggle source

Is the list empty?

@return [Boolean] true if empty

# File lib/standup_md/entry_list.rb, line 162
def empty?
  @entries.empty?
end
filter(start_date, end_date) click to toggle source

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
filter!(start_date, end_date) click to toggle source

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
find(key) click to toggle source

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
first() click to toggle source

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
last() click to toggle source

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
size() click to toggle source

How many entries are in the list.

@return [Integer]

# File lib/standup_md/entry_list.rb, line 154
def size
  @entries.size
end
sort() click to toggle source

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
sort!() click to toggle source

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
sort_reverse() click to toggle source

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
to_h() click to toggle source

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
to_json() click to toggle source

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