Class: GeoDistance::Distance
- Inherits:
-
Object
- Object
- GeoDistance::Distance
- Defined in:
- lib/geo-distance.rb
Defined Under Namespace
Classes: Unit
Instance Attribute Summary collapse
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(distance, unit = nil) ⇒ Distance
constructor
A new instance of Distance.
Constructor Details
#initialize(distance, unit = nil) ⇒ Distance
Returns a new instance of Distance.
57 58 59 60 61 62 63 |
# File 'lib/geo-distance.rb', line 57 def initialize distance, unit = nil @distance = distance return if !unit raise ArgumentError, "Invalid unit: #{unit} - must be one of #{GeoDistance.units}" if !GeoDistance.units.include?(unit.to_sym) @unit = unit.to_sym end |
Instance Attribute Details
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
55 56 57 |
# File 'lib/geo-distance.rb', line 55 def distance @distance end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
55 56 57 |
# File 'lib/geo-distance.rb', line 55 def unit @unit end |
Instance Method Details
#[](key) ⇒ Object
65 66 67 68 69 |
# File 'lib/geo-distance.rb', line 65 def [] key method = :"delta_#{key}" raise ArgumentError, "Invalid unit key #{key}" if !respond_to? method Distance.send "in_#{key}", send(method) end |