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 =
Section identifiers supported by each standup entry.
%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(config: StandupMD.config.entry, date: Date.today, current: nil, previous: nil, impediments: nil, notes: nil) ⇒ 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.
Constructor Details
#initialize(date, current, previous, impediments, notes = []) ⇒ Entry
Constructs instance of StandupMD::Entry.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/standup_md/entry.rb', line 80 def initialize(date, current, previous, impediments, notes = []) raise unless date.is_a?(Date) @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.
32 33 34 |
# File 'lib/standup_md/entry.rb', line 32 def date @date end |
Class Method Details
.config ⇒ StandupMD::Config::Entry
Access to the class’s configuration.
22 23 24 |
# File 'lib/standup_md/entry.rb', line 22 def self.config StandupMD.config.entry end |
.create(config: StandupMD.config.entry, date: Date.today, current: nil, previous: nil, impediments: nil, notes: nil) ⇒ 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/standup_md/entry.rb', line 51 def self.create( config: StandupMD.config.entry, date: Date.today, current: nil, previous: nil, impediments: nil, notes: nil ) new( date, current || config.current, previous || config.previous, impediments || config.impediments, notes || config.notes ).tap { |entry| yield entry if block_given? } end |
Instance Method Details
#<=>(other) ⇒ Object
Sorting method for Comparable. Entries are compared by date.
125 126 127 |
# File 'lib/standup_md/entry.rb', line 125 def <=>(other) date <=> other.date end |
#section(type) ⇒ StandupMD::Section
Find a section by type.
119 120 121 |
# File 'lib/standup_md/entry.rb', line 119 def section(type) @sections[type.to_sym] ||= Section.new(type) end |
#sections ⇒ Array<StandupMD::Section>
Sections for this entry.
109 110 111 |
# File 'lib/standup_md/entry.rb', line 109 def sections SECTION_TYPES.map { |type| section(type) } end |
#to_h ⇒ Hash
Entry as a hash.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/standup_md/entry.rb', line 133 def to_h { date => { "current" => current, "previous" => previous, "impediments" => impediments, "notes" => notes } } end |