Class: Locations::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/oeffi/locations.rb

Constant Summary collapse

STATION =
0
ADDRESS =
1
POI =
2
ANY =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def id
  @id
end

#latObject

Returns the value of attribute lat.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def lat
  @lat
end

#locObject

Returns the value of attribute loc.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def loc
  @loc
end

#lonObject

Returns the value of attribute lon.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def lon
  @lon
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def name
  @name
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/oeffi/locations.rb', line 6

def type
  @type
end

Instance Method Details

#as_jsonObject



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_toObject



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