Class: StandupMD::EntryList
- Inherits:
-
Object
- Object
- StandupMD::EntryList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/standup_md/entry_list.rb
Overview
Enumerable list of entries.
Class Method Summary collapse
-
.config ⇒ StandupMD::Config::EntryList
Access to the class’s configuration.
Instance Method Summary collapse
-
#<<(entry) ⇒ Array
Appends entries to list.
-
#filter(start_date, end_date) ⇒ Array
Returns entries that are between the start and end date.
-
#filter!(start_date, end_date) ⇒ Array
Replaces entries with results of filter.
-
#find(date) ⇒ StandupMD::Entry
Finds an entry based on date.
-
#initialize(*entries) ⇒ StandupMD::EntryList
constructor
Contruct a list.
-
#sort ⇒ StandupMD::EntryList
Returns a copy of self sorted by date.
-
#sort! ⇒ StandupMD::EntryList
Replace entries with sorted entries by date.
-
#sort_reverse ⇒ StandupMD::EntryList
Returns a copy of self sorted by date, reversed.
-
#to_h ⇒ Hash
The list as a hash, with the dates as keys.
-
#to_json ⇒ String
The entry list as a json object.
Constructor Details
#initialize(*entries) ⇒ StandupMD::EntryList
Contruct a list. Can pass any amount of StandupMD::Entry instances.
26 27 28 29 30 31 |
# File 'lib/standup_md/entry_list.rb', line 26 def initialize(*entries) entries.each { |entry| validate_entry(entry) } @config = self.class.config @entries = entries end |
Class Method Details
.config ⇒ StandupMD::Config::EntryList
Access to the class’s configuration.
16 17 18 |
# File 'lib/standup_md/entry_list.rb', line 16 def self.config @config ||= StandupMD.config.entry_list end |
Instance Method Details
#<<(entry) ⇒ Array
Appends entries to list.
39 40 41 42 43 |
# File 'lib/standup_md/entry_list.rb', line 39 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.
90 91 92 93 94 |
# File 'lib/standup_md/entry_list.rb', line 90 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) ⇒ Array
Replaces entries with results of filter.
104 105 106 107 |
# File 'lib/standup_md/entry_list.rb', line 104 def filter!(start_date, end_date) @entries = filter(start_date, end_date) self end |
#find(date) ⇒ StandupMD::Entry
Finds an entry based on date. This method assumes the list has already been sorted.
52 53 54 |
# File 'lib/standup_md/entry_list.rb', line 52 def find(date) entries.bsearch { |entry| date <=> entry.date } end |
#sort ⇒ StandupMD::EntryList
Returns a copy of self sorted by date.
60 61 62 |
# File 'lib/standup_md/entry_list.rb', line 60 def sort self.class.new(*@entries.sort) end |
#sort! ⇒ StandupMD::EntryList
Replace entries with sorted entries by date.
68 69 70 71 |
# File 'lib/standup_md/entry_list.rb', line 68 def sort! @entries = @entries.sort self end |
#sort_reverse ⇒ StandupMD::EntryList
Returns a copy of self sorted by date, reversed.
77 78 79 |
# File 'lib/standup_md/entry_list.rb', line 77 def sort_reverse self.class.new(*@entries.sort.reverse) end |
#to_h ⇒ Hash
The list as a hash, with the dates as keys.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/standup_md/entry_list.rb', line 113 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 |
#to_json ⇒ String
The entry list as a json object.
131 132 133 |
# File 'lib/standup_md/entry_list.rb', line 131 def to_json to_h.to_json end |