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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*entries) ⇒ StandupMD::EntryList

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

Parameters:



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

.configStandupMD::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.

Parameters:

Returns:

  • (Array)


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.

Parameters:

  • start_date (Date)
  • end_date (Date)

Returns:

  • (Array)


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.

Parameters:

  • start_date (Date)
  • end_date (Date)

Returns:

  • (Array)


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.

Parameters:

  • date (Date)

Returns:



52
53
54
# File 'lib/standup_md/entry_list.rb', line 52

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

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

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

Returns:

  • (Hash)


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_jsonString

The entry list as a json object.

Returns:

  • (String)


131
132
133
# File 'lib/standup_md/entry_list.rb', line 131

def to_json
  to_h.to_json
end