Class: URBANopt::Reporting::DefaultReports::EndUses
- Inherits:
-
Object
- Object
- URBANopt::Reporting::DefaultReports::EndUses
- Defined in:
- lib/urbanopt/reporting/default_reports/end_uses.rb
Overview
Enduses class inlclude results for each fuel type.
Instance Attribute Summary collapse
-
#additional_fuel ⇒ Object
:nodoc:.
-
#district_cooling ⇒ Object
:nodoc:.
-
#district_heating ⇒ Object
:nodoc:.
-
#electricity ⇒ Object
:nodoc:.
-
#natural_gas ⇒ Object
:nodoc:.
-
#water ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assigns default values if values do not exist.
-
#initialize(hash = {}) ⇒ EndUses
constructor
EndUses class intialize end_uses(fuel type) attributes:
:electricity,:natural_gas,:additional_fuel,:district_cooling,:district_heating,:water. -
#merge_end_uses!(new_end_uses) ⇒ Object
Aggregates the values of each EndUse attribute.
-
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
Constructor Details
#initialize(hash = {}) ⇒ EndUses
EndUses class intialize end_uses(fuel type) attributes: :electricity , :natural_gas , :additional_fuel , :district_cooling , :district_heating , :water
- parameters:
-
hash- Hash - A hash which may contain a deserialized end_uses.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 50 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @electricity = EndUse.new(hash[:electricity]) @natural_gas = EndUse.new(hash[:natural_gas]) @additional_fuel = EndUse.new(hash[:additional_fuel]) @district_cooling = EndUse.new(hash[:district_cooling]) @district_heating = EndUse.new(hash[:district_heating]) @water = EndUse.new(hash[:water]) # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end |
Instance Attribute Details
#additional_fuel ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def additional_fuel @additional_fuel end |
#district_cooling ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def district_cooling @district_cooling end |
#district_heating ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def district_heating @district_heating end |
#electricity ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def electricity @electricity end |
#natural_gas ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def natural_gas @natural_gas end |
#water ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 42 def water @water end |
Instance Method Details
#defaults ⇒ Object
Assigns default values if values do not exist.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 110 def defaults hash = {} hash[:electricity] = EndUse.new.to_hash hash[:natural_gas] = EndUse.new.to_hash hash[:additional_fuel] = EndUse.new.to_hash hash[:district_cooling] = EndUse.new.to_hash hash[:district_heating] = EndUse.new.to_hash hash[:water] = EndUse.new.to_hash return hash end |
#merge_end_uses!(new_end_uses) ⇒ Object
Aggregates the values of each EndUse attribute.
- Parameters:
-
new_end_uses- EndUses - An object of EndUses class.
128 129 130 131 132 133 134 135 136 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 128 def merge_end_uses!(new_end_uses) # modify the existing_period by summing up the results ; # sum results only if they exist @electricity.merge_end_use!(new_end_uses.electricity) @natural_gas.merge_end_use!(new_end_uses.natural_gas) @additional_fuel.merge_end_use!(new_end_uses.additional_fuel) @district_cooling.merge_end_use!(new_end_uses.district_cooling) @district_heating.merge_end_use!(new_end_uses.district_heating) return self end |
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
-
Exclude attributes with nil values.
-
Validate end_uses hash properties against schema.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 72 def to_hash result = {} electricity_hash = @electricity.to_hash if @electricity.to_hash electricity_hash.delete_if { |k, v| v.nil? } result[:electricity] = electricity_hash if @electricity natural_gas_hash = @natural_gas.to_hash if @natural_gas natural_gas_hash.delete_if { |k, v| v.nil? } result[:natural_gas] = natural_gas_hash if @natural_gas additional_fuel_hash = @additional_fuel.to_hash if @additional_fuel additional_fuel_hash.delete_if { |k, v| v.nil? } result[:additional_fuel] = additional_fuel_hash if @additional_fuel district_cooling_hash = @district_cooling.to_hash if @district_cooling district_cooling_hash.delete_if { |k, v| v.nil? } result[:district_cooling] = district_cooling_hash if @district_cooling district_heating_hash = @district_heating.to_hash if @district_heating district_heating_hash.delete_if { |k, v| v.nil? } result[:district_heating] = district_heating_hash if @district_heating water_hash = @water.to_hash if @water water_hash.delete_if { |k, v| v.nil? } result[:water] = water_hash if @water # validate end_uses properties against schema if @@validator.validate(@@schema[:definitions][:EndUses][:properties], result).any? raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:EndUses][:properties], result)}" end return result end |