Class: StandupMD::Entry
- Inherits:
-
Object
- Object
- StandupMD::Entry
- Includes:
- Comparable
- Defined in:
- lib/standup_md/entry.rb
Overview
Class for handling single entries. Includes the comparable module, and compares by date.
Constant Summary collapse
- SECTION_TYPES =
%i[current previous impediments notes].freeze
Instance Attribute Summary collapse
-
#date ⇒ Date
The date of the entry.
Class Method Summary collapse
-
.config ⇒ StandupMD::Config::Entry
Access to the class’s configuration.
-
.create ⇒ StandupMD::Entry
Creates a generic entry.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sorting method for Comparable.
-
#initialize(date, current, previous, impediments, notes = []) ⇒ Entry
constructor
Constructs instance of
StandupMD::Entry. -
#section(type) ⇒ StandupMD::Section
Find a section by type.
-
#sections ⇒ Array<StandupMD::Section>
Sections for this entry.
-
#to_h ⇒ Hash
Entry as a hash .
-
#to_json ⇒ String
Entry as a json object.
Constructor Details
#initialize(date, current, previous, impediments, notes = []) ⇒ Entry
Constructs instance of StandupMD::Entry.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/standup_md/entry.rb', line 58 def initialize(date, current, previous, impediments, notes = []) raise unless date.is_a?(Date) @config = self.class.config @date = date @sections = {} self.current = current self.previous = previous self.impediments = impediments self.notes = notes end |
Instance Attribute Details
#date ⇒ Date
The date of the entry.
29 30 31 |
# File 'lib/standup_md/entry.rb', line 29 def date @date end |
Class Method Details
.config ⇒ StandupMD::Config::Entry
Access to the class’s configuration.
19 20 21 |
# File 'lib/standup_md/entry.rb', line 19 def self.config @config ||= StandupMD.config.entry end |
.create ⇒ StandupMD::Entry
Creates a generic entry. Default values can be set via configuration. Yields the entry if a block is passed so you can change values.
36 37 38 39 40 41 42 43 44 |
# File 'lib/standup_md/entry.rb', line 36 def self.create new( Date.today, config.current, config.previous, config.impediments, config.notes ).tap { |entry| yield entry if block_given? } end |
Instance Method Details
#<=>(other) ⇒ Object
Sorting method for Comparable. Entries are compared by date.
104 105 106 |
# File 'lib/standup_md/entry.rb', line 104 def <=>(other) date <=> other.date end |
#section(type) ⇒ StandupMD::Section
Find a section by type.
98 99 100 |
# File 'lib/standup_md/entry.rb', line 98 def section(type) @sections[type.to_sym] ||= Section.new(type) end |
#sections ⇒ Array<StandupMD::Section>
Sections for this entry.
88 89 90 |
# File 'lib/standup_md/entry.rb', line 88 def sections SECTION_TYPES.map { |type| section(type) } end |
#to_h ⇒ Hash
Entry as a hash .
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/standup_md/entry.rb', line 112 def to_h { date => { "current" => current, "previous" => previous, "impediments" => impediments, "notes" => notes } } end |
#to_json ⇒ String
Entry as a json object.
127 128 129 |
# File 'lib/standup_md/entry.rb', line 127 def to_json to_h.to_json end |