Class: URBANopt::Reporting::DefaultReports::PowerDistribution
- Inherits:
-
Object
- Object
- URBANopt::Reporting::DefaultReports::PowerDistribution
- Defined in:
- lib/urbanopt/reporting/default_reports/power_distribution.rb
Overview
power_distributio include eletrical power distribution systems information.
Instance Attribute Summary collapse
-
#over_voltage_hours ⇒ Object
:nodoc:.
-
#under_voltage_hours ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assigns default values if attribute values do not exist.
-
#initialize(hash = {}) ⇒ PowerDistribution
constructor
PowerDistrinution class intialize all power_distribution attributes:
:under_voltage_hours,:over_voltage_hours. -
#merge_power_distribition ⇒ Object
Merges muliple power distribution results together.
-
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
Constructor Details
#initialize(hash = {}) ⇒ PowerDistribution
PowerDistrinution class intialize all power_distribution attributes: :under_voltage_hours , :over_voltage_hours
- parameters:
-
hash- Hash - A hash which may contain a deserialized power_distribution.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 61 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @under_voltage_hours = hash[:under_voltage_hours] @over_voltage_hours = hash[:over_voltage_hours] # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end |
Instance Attribute Details
#over_voltage_hours ⇒ Object
:nodoc:
53 54 55 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 53 def over_voltage_hours @over_voltage_hours end |
#under_voltage_hours ⇒ Object
:nodoc:
53 54 55 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 53 def under_voltage_hours @under_voltage_hours end |
Instance Method Details
#defaults ⇒ Object
Assigns default values if attribute values do not exist.
76 77 78 79 80 81 82 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 76 def defaults hash = {} hash[:under_voltage_hours] = nil hash[:over_voltage_hours] = nil return hash end |
#merge_power_distribition ⇒ Object
Merges muliple power distribution results together.
new_costs - Array - An array of ConstructionCost objects.
107 108 109 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 107 def merge_power_distribition # method to be developed for any attributes to be aggregated or merged end |
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
-
Exclude attributes with nil values.
-
Validate power_distribution hash properties against schema.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 90 def to_hash result = {} result[:under_voltage_hours] = @under_voltage_hours if @under_voltage_hours result[:over_voltage_hours] = @over_voltage_hours if @over_voltage_hours # validate power_distribution properties against schema if @@validator.validate(@@schema[:definitions][:PowerDistribution][:properties], result).any? raise "power_distribution properties does not match schema: #{@@validator.validate(@@schema[:definitions][:PowerDistribution][:properties], result)}" end return result end |