Class: URBANopt::Reporting::DefaultReports::PowerDistribution

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/reporting/default_reports/power_distribution.rb

Overview

power_distributio include eletrical power distribution systems information.

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 51

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_hoursObject

:nodoc:



43
44
45
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 43

def over_voltage_hours
  @over_voltage_hours
end

#under_voltage_hoursObject

:nodoc:



43
44
45
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 43

def under_voltage_hours
  @under_voltage_hours
end

Instance Method Details

#defaultsObject

Assigns default values if attribute values do not exist.



66
67
68
69
70
71
72
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 66

def defaults
  hash = {}
  hash[:under_voltage_hours] = nil
  hash[:over_voltage_hours] = nil

  return hash
end

#merge_power_distribitionObject

Merges muliple power distribution results together.

new_costs - Array - An array of ConstructionCost objects.



97
98
99
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 97

def merge_power_distribition
  # method to be developed for any attributes to be aggregated or merged
end

#to_hashObject

Converts to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate power_distribution hash properties against schema.



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 80

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