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


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/standup_md/entry.rb', line 62

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)


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

def date
  @date
end

Class Method Details

.configStandupMD::Config::Entry

Access to the class’s configuration.



23
24
25
# File 'lib/standup_md/entry.rb', line 23

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:



40
41
42
43
44
45
46
47
48
# File 'lib/standup_md/entry.rb', line 40

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.



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

def <=>(other)
  date <=> other.date
end

#section(type) ⇒ StandupMD::Section

Find a section by type.

Parameters:

  • type (Symbol, String)

Returns:



102
103
104
# File 'lib/standup_md/entry.rb', line 102

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

#sectionsArray<StandupMD::Section>

Sections for this entry.

Returns:



92
93
94
# File 'lib/standup_md/entry.rb', line 92

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

#to_hHash

Entry as a hash .

Returns:

  • (Hash)


116
117
118
119
120
121
122
123
124
125
# File 'lib/standup_md/entry.rb', line 116

def to_h
  {
    date => {
      "current" => current,
      "previous" => previous,
      "impediments" => impediments,
      "notes" => notes
    }
  }
end

#to_jsonString

Entry as a json object.

Returns:

  • (String)


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

def to_json
  to_h.to_json
end