Class: StandupMD::Entry

Inherits:
Object
  • Object
show all
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.

Returns:

  • (Array<Symbol>)
%i[current previous impediments notes].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, current, previous, impediments, notes = []) ⇒ Entry

Constructs instance of StandupMD::Entry.

Parameters:

  • date (Date)
  • current (Array)
  • previous (Array)
  • impediments (Array)
  • notes (Array) (defaults to: [])


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

#dateDate

The date of the entry.

Parameters:

  • date (Date)

Returns:

  • (Date)


32
33
34
# File 'lib/standup_md/entry.rb', line 32

def date
  @date
end

Class Method Details

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

Parameters:

  • config (StandupMD::Config::Entry) (defaults to: StandupMD.config.entry)
  • date (Date) (defaults to: Date.today)
  • current (Array, nil) (defaults to: nil)
  • previous (Array, nil) (defaults to: nil)
  • impediments (Array, nil) (defaults to: nil)
  • notes (Array, nil) (defaults to: nil)

Returns:



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.

Parameters:

  • type (Symbol, String)

Returns:



119
120
121
# File 'lib/standup_md/entry.rb', line 119

def section(type)
  @sections[type.to_sym] ||= Section.new(type)
end

#sectionsArray<StandupMD::Section>

Sections for this entry.

Returns:



109
110
111
# File 'lib/standup_md/entry.rb', line 109

def sections
  SECTION_TYPES.map { |type| section(type) }
end

#to_hHash

Entry as a hash.

Returns:

  • (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