Class: DublinBikes::Station

Inherits:
Object
  • Object
show all
Defined in:
lib/dublin_bikes/station.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(marker) ⇒ Station

Returns a new instance of Station.



5
6
7
8
9
10
# File 'lib/dublin_bikes/station.rb', line 5

def initialize(marker)
  @id = marker.number
  @address = marker.address
  @latitude = marker.lat
  @longitude = marker.lng
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



3
4
5
# File 'lib/dublin_bikes/station.rb', line 3

def address
  @address
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/dublin_bikes/station.rb', line 3

def id
  @id
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



3
4
5
# File 'lib/dublin_bikes/station.rb', line 3

def latitude
  @latitude
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



3
4
5
# File 'lib/dublin_bikes/station.rb', line 3

def longitude
  @longitude
end

Instance Method Details

#distance_to(m_lat, m_lng) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dublin_bikes/station.rb', line 12

def distance_to(m_lat, m_lng)
  d_lat = (@latitude - m_lat).to_rad
  d_lng = (@longitude - m_lng).to_rad

  a = Math.sin(d_lat / 2) * Math.sin(d_lat / 2) +
    Math.cos(m_lat.to_rad) * Math.cos(@latitude.to_rad) *
    Math.sin(d_lng / 2) * Math.sin(d_lng / 2)

  c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))

  6371 * c
end