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 =
%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: [])


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

#dateDate

The date of the entry.

Parameters:

  • date (Date)

Returns:

  • (Date)


29
30
31
# File 'lib/standup_md/entry.rb', line 29

def date
  @date
end

Class Method Details

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

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

Returns:



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.

Parameters:

  • type (Symbol, String)

Returns:



98
99
100
# File 'lib/standup_md/entry.rb', line 98

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

#sectionsArray<StandupMD::Section>

Sections for this entry.

Returns:



88
89
90
# File 'lib/standup_md/entry.rb', line 88

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

#to_hHash

Entry as a hash .

Returns:

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

Entry as a json object.

Returns:

  • (String)


127
128
129
# File 'lib/standup_md/entry.rb', line 127

def to_json
  to_h.to_json
end