Class: DublinBikes::Station
- Inherits:
-
Object
- Object
- DublinBikes::Station
- Defined in:
- lib/dublin_bikes/station.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
Instance Method Summary collapse
- #distance_to(m_lat, m_lng) ⇒ Object
-
#initialize(marker) ⇒ Station
constructor
A new instance of Station.
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
#address ⇒ Object (readonly)
Returns the value of attribute address.
3 4 5 |
# File 'lib/dublin_bikes/station.rb', line 3 def address @address end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/dublin_bikes/station.rb', line 3 def id @id end |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/dublin_bikes/station.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object (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 |