Class: Timetrap::Formatters::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/timetrap/formatters/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ Json

Returns a new instance of Json.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/timetrap/formatters/json.rb', line 16

def initialize entries
  @output = entries.map do |e|
    next unless e.end

    e.values.inject({}) do |h, (k,v)|
      h[k] = v
      h[k] = e.public_send(k) if %i[end start].include?(k)
      h
    end
  end.compact.to_json
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



14
15
16
# File 'lib/timetrap/formatters/json.rb', line 14

def output
  @output
end