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.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 25

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:



17
18
19
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 17

def latitude_deg
  @latitude_deg
end

#longitude_degObject

:nodoc:



17
18
19
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 17

def longitude_deg
  @longitude_deg
end

#surface_elevation_ftObject

:nodoc:



17
18
19
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 17

def surface_elevation_ft
  @surface_elevation_ft
end

#weather_filenameObject

:nodoc:



17
18
19
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 17

def weather_filename
  @weather_filename
end

Instance Method Details

#defaultsObject

Assign default values if values does not exist



63
64
65
66
67
68
69
70
71
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 63

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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/urbanopt/reporting/default_reports/location.rb', line 45

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