Class: URBANopt::Reporting::DefaultReports::Location

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

Overview

Location include all location information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Location

Location class initialize location attributes: :latitude_deg , :longitude_deg , :surface_elevation_ft , :weather_filename

parameters:

hash - Hash - A hash which may contain a deserialized location.



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

def initialize(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)

  @latitude_deg = hash[:latitude_deg]
  @longitude_deg = hash[:longitude_deg]
  @surface_elevation_ft = hash[:surface_elevation_ft]
  @weather_filename = hash[:weather_filename]

  # initialize class variables @@validator and @@schema
  @@validator ||= Validator.new
  @@schema ||= @@validator.schema
end

Instance Attribute Details

#latitude_degObject

:nodoc:



42
43
44
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 42

def latitude_deg
  @latitude_deg
end

#longitude_degObject

:nodoc:



42
43
44
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 42

def longitude_deg
  @longitude_deg
end

#surface_elevation_ftObject

:nodoc:



42
43
44
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 42

def surface_elevation_ft
  @surface_elevation_ft
end

#weather_filenameObject

:nodoc:



42
43
44
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 42

def weather_filename
  @weather_filename
end

Instance Method Details

#defaultsObject

Assign default values if values does not exist



87
88
89
90
91
92
93
94
95
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 87

def defaults
  hash = {}
  hash[:latitude_deg] = nil
  hash[:longitude_deg] = nil
  hash[:surface_elevation_ft] = nil
  hash[:weather_filename] = nil

  return hash
end

#to_hashObject

Convert to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate location hash properties against schema.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 69

def to_hash
  result = {}
  result[:latitude_deg] = @latitude_deg if @latitude_deg
  result[:longitude_deg] = @longitude_deg if @longitude_deg
  result[:surface_elevation_ft] = @surface_elevation_ft if @surface_elevation_ft
  result[:weather_filename] = @weather_filename if @weather_filename

  # validate location properties against schema
  if @@validator.validate(@@schema[:definitions][:Location][:properties], result).any?
    raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:Location][:properties], result)}"
  end

  return result
end