Class: Geckoboard::PayloadFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/geckoboard/payload_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ PayloadFormatter

Returns a new instance of PayloadFormatter.



5
6
7
# File 'lib/geckoboard/payload_formatter.rb', line 5

def initialize(dataset)
  @dataset = dataset
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



3
4
5
# File 'lib/geckoboard/payload_formatter.rb', line 3

def dataset
  @dataset
end

Instance Method Details

#format(payload) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/geckoboard/payload_formatter.rb', line 9

def format(payload)
  payload.map do |item|
    item.inject({}) do |hash, (field_name, value)|
      field_name = field_name.to_s

      value = case field_type(field_name)
              when 'date'     then format_date(value)
              when 'datetime' then format_datetime(value)
              else
                value
              end

      hash.merge(field_name => value)
    end
  end
end