class URBANopt::Reporting::DefaultReports::Date
Date
class include information of simulation run date.
Public Class Methods
new(hash = {})
click to toggle source
Date
class intialize all date attributes: :month
, :day_of_month
, :year
- parameters:
-
hash
- Hash - A hash which may contain a deserialized date.
# File lib/urbanopt/reporting/default_reports/date.rb, line 26 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @month = hash[:month].to_i @day_of_month = hash[:day_of_month].to_i @year = hash[:year].to_i # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end
Public Instance Methods
defaults()
click to toggle source
Assigns default values if values do not exist.
# File lib/urbanopt/reporting/default_reports/date.rb, line 62 def defaults hash = {} hash[:month] = nil hash[:day_of_month] = nil hash[:year] = nil return hash end
to_hash()
click to toggle source
Converts to a hash equivalent for JSON serialization.
-
Exclude attributes with nil values.
-
Validate date properties against schema.
# File lib/urbanopt/reporting/default_reports/date.rb, line 45 def to_hash result = {} result[:month] = @month if @month result[:day_of_month] = @day_of_month if @day_of_month result[:year] = @year if @year # validate date hash properties against schema if @@validator.validate(@@schema[:definitions][:Date][:properties], result).any? raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:Date][:properties], result)}" end return result end