Class: Locations::Location
- Inherits:
-
Object
- Object
- Locations::Location
- Defined in:
- lib/oeffi/locations.rb
Constant Summary collapse
- STATION =
0
- ADDRESS =
1
- POI =
2
- ANY =
3
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#loc ⇒ Object
Returns the value of attribute loc.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
- #distance_to ⇒ Object
-
#initialize(javaStation) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(javaStation) ⇒ Location
Returns a new instance of Location.
13 14 15 16 17 18 19 |
# File 'lib/oeffi/locations.rb', line 13 def initialize(javaStation) @type = javaStation.type.to_s @id = javaStation.id @name = javaStation.name @lat = javaStation.lat.to_f / 1000000 @lon = javaStation.lon.to_f / 1000000 end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def id @id end |
#lat ⇒ Object
Returns the value of attribute lat.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def lat @lat end |
#loc ⇒ Object
Returns the value of attribute loc.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def loc @loc end |
#lon ⇒ Object
Returns the value of attribute lon.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def lon @lon end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/oeffi/locations.rb', line 6 def type @type end |
Instance Method Details
#as_json ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/oeffi/locations.rb', line 21 def as_json hash = {} [:id, :type, :name, :lat, :lon].each do |sym| hash[sym] = self.send sym end unless @lat.nil? or @loc.nil? hash[:distance_to] = distance_to end return hash end |
#distance_to ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/oeffi/locations.rb', line 32 def distance_to return 0 unless @lat > 0 and @lon > 0 return 0 unless @loc[:lat] > 0 and @loc[:lon] > 0 from = Geokit::LatLng.new @lat, @lon to = Geokit::LatLng.new loc[:lat], loc[:lon] (from.distance_to to, unit: :km) * 1000 end |