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.

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


79
80
81
82
83
84
85
86
87
88
# File 'lib/standup_md/entry.rb', line 79

def initialize(date, current, previous, impediments, notes = [])
  raise unless date.is_a?(Date)

  @config = self.class.config
  @date = date
  @current = current
  @previous = previous
  @impediments = impediments
  @notes = notes
end

Instance Attribute Details

#currentArray

The tasks for today.

Returns:

  • (Array)


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

def current
  @current
end

#dateDate

The date of the entry.

Parameters:

  • date (Date)

Returns:

  • (Date)


26
27
28
# File 'lib/standup_md/entry.rb', line 26

def date
  @date
end

#impedimentsArray

Impediments for this entry.

Returns:

  • (Array)


44
45
46
# File 'lib/standup_md/entry.rb', line 44

def impediments
  @impediments
end

#notesArray

Nnotes to add to this entry.

Returns:

  • (Array)


50
51
52
# File 'lib/standup_md/entry.rb', line 50

def notes
  @notes
end

#previousArray

The tasks from the previous day.

Returns:

  • (Array)


38
39
40
# File 'lib/standup_md/entry.rb', line 38

def previous
  @previous
end

Class Method Details

.configStandupMD::Config::Entry

Access to the class’s configuration.



16
17
18
# File 'lib/standup_md/entry.rb', line 16

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:



57
58
59
60
61
62
63
64
65
# File 'lib/standup_md/entry.rb', line 57

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.



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

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

#to_hHash

Entry as a hash .

Returns:

  • (Hash)


100
101
102
103
104
105
106
107
108
109
# File 'lib/standup_md/entry.rb', line 100

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

#to_jsonString

Entry as a json object.

Returns:

  • (String)


115
116
117
# File 'lib/standup_md/entry.rb', line 115

def to_json
  to_h.to_json
end