Class: StandupMD::EntryList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/standup_md/entry_list.rb

Overview

Enumerable list of entries.

Instance Method Summary collapse

Constructor Details

#initialize(*entries) ⇒ StandupMD::EntryList

Construct a list. Can pass any amount of StandupMD::Entry instances.

Parameters:



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.

Parameters:

Returns:



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.

Parameters:

  • start_date (Date)
  • end_date (Date)

Returns:

  • (Array)


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.

Parameters:

  • start_date (Date)
  • end_date (Date)

Returns:



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.

Parameters:

  • date (Date)

Returns:



43
44
45
# File 'lib/standup_md/entry_list.rb', line 43

def find(date)
  entries.bsearch { |entry| date <=> entry.date }
end

#sortStandupMD::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_reverseStandupMD::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_hHash

The list as a hash, with the dates as keys.

Returns:

  • (Hash)


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