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 16
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 26
def initialize(*entries)
  @config = self.class.config
  unless entries.all? { |e| e.is_a?(StandupMD::Entry) }
    raise ArgumentError, 'Entry must be an 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 40
def <<(entry)
  unless entry.is_a?(StandupMD::Entry)
    raise ArgumentError, 'Entry must be an instance of StandupMD::Entry'
  end
  @entries << entry
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(date) click to toggle source

Finds an entry based on date. This method assumes the list has already been sorted.

@param [Date] date

@return [StandupMD::Entry]

# File lib/standup_md/entry_list.rb, line 54
def find(date)
  entries.bsearch { |e| e.date == date }
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

Delegators

↑ top

Public Instance Methods

@entries() click to toggle source

The following are forwarded to @entries, which is the underly 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.

# File lib/standup_md/entry_list.rb, line 147
def_delegators :@entries, :each, :empty?, :size, :first, :last