Class: HeatLossSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/serializers/heat_loss_serializer.rb

Overview

Only use this with a json or jsonb back end column

Class Method Summary collapse

Class Method Details

.cleanup_hash(hash) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/serializers/heat_loss_serializer.rb', line 12

def self.cleanup_hash(hash)
  return {} if hash.blank?

  if hash['avg_temperature_ranges'].present?
    hash['avg_temperature_ranges'] = hash['avg_temperature_ranges'].map do |v|
      v['range'] = v['range'].map(&:to_d)
      v
    end
  end
  if hash['hlc_by_object'].present?
    hash['hlc_by_object'] = hash['hlc_by_object'].map do |v|
      v['heat_loss'] = v['heat_loss'].to_d
      v
    end
  end
  hash
end

.dump(hash) ⇒ Object



4
5
6
# File 'app/serializers/heat_loss_serializer.rb', line 4

def self.dump(hash)
  cleanup_hash(hash)
end

.load(hash) ⇒ Object



8
9
10
# File 'app/serializers/heat_loss_serializer.rb', line 8

def self.load(hash)
  cleanup_hash(hash)
end