Class: HeatLossSerializer
- Inherits:
-
Object
- Object
- HeatLossSerializer
- Defined in:
- app/serializers/heat_loss_serializer.rb
Overview
Note:
Only use this with a json or jsonb back end column.
Serializes a heat-loss calculation result hash for a JSON/JSONB column,
coercing temperature ranges and per-object heat-loss values to BigDecimal.
Class Method Summary collapse
-
.cleanup_hash(hash) ⇒ Hash
Coerces
avg_temperature_rangesrange bounds andhlc_by_objectheat-loss values toBigDecimal, returning an empty hash for blank input. -
.dump(hash) ⇒ Hash
Prepares a heat-loss hash for database storage.
-
.load(hash) ⇒ Hash
Restores a heat-loss hash read from the database.
Class Method Details
.cleanup_hash(hash) ⇒ Hash
Coerces avg_temperature_ranges range bounds and hlc_by_object heat-loss
values to BigDecimal, returning an empty hash for blank input.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/serializers/heat_loss_serializer.rb', line 29 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) ⇒ Hash
Prepares a heat-loss hash for database storage.
12 13 14 |
# File 'app/serializers/heat_loss_serializer.rb', line 12 def self.dump(hash) cleanup_hash(hash) end |
.load(hash) ⇒ Hash
Restores a heat-loss hash read from the database.
20 21 22 |
# File 'app/serializers/heat_loss_serializer.rb', line 20 def self.load(hash) cleanup_hash(hash) end |