class Distance
Constants
- MARATHON
- VERSION
Attributes
distance_in_meters[R]
Public Class Methods
feet(n)
click to toggle source
# File lib/distance.rb, line 33 def self.feet(n) new(n * Multiplier::FOOT) end
inches(n)
click to toggle source
# File lib/distance.rb, line 29 def self.inches(n) new(n * Multiplier::INCH) end
kilometers(n)
click to toggle source
# File lib/distance.rb, line 25 def self.kilometers(n) new(n * Multiplier::KILOMETER) end
meters(n)
click to toggle source
# File lib/distance.rb, line 21 def self.meters(n) new(n) end
miles(n)
click to toggle source
# File lib/distance.rb, line 37 def self.miles(n) new(n * Multiplier::MILE) end
Private Class Methods
new(distance_in_meters)
click to toggle source
# File lib/distance.rb, line 13 def initialize(distance_in_meters) @distance_in_meters = distance_in_meters.to_f end
Public Instance Methods
*(multiplier)
click to toggle source
# File lib/distance.rb, line 75 def *(multiplier) unless multiplier.is_a?(Numeric) raise ArgumentError, 'Can only multiply a Distance with a number' end Distance.meters(to_f * multiplier) end
+(other)
click to toggle source
# File lib/distance.rb, line 61 def +(other) unless other.is_a?(Distance) raise ArgumentError, 'Can only add a Distance to a Distance' end Distance.meters(to_f + other.to_f) end
-(other)
click to toggle source
# File lib/distance.rb, line 68 def -(other) unless other.is_a?(Distance) raise ArgumentError, 'Can only subtract a Distance from a Distance' end Distance.meters(to_f - other.to_f) end
/(divisor)
click to toggle source
# File lib/distance.rb, line 82 def /(divisor) unless divisor.is_a?(Numeric) raise ArgumentError, 'Can only divide a Distance by a number' end Distance.meters(to_f / divisor) end
<(other)
click to toggle source
# File lib/distance.rb, line 104 def <(other) return false unless other.is_a?(Distance) to_f < other.to_f end
<=(other)
click to toggle source
# File lib/distance.rb, line 109 def <=(other) return false unless other.is_a?(Distance) to_f <= other.to_f end
==(other)
click to toggle source
# File lib/distance.rb, line 99 def ==(other) return false unless other.is_a?(Distance) to_f == other.to_f end
>(other)
click to toggle source
# File lib/distance.rb, line 89 def >(other) return false unless other.is_a?(Distance) to_f > other.to_f end
>=(other)
click to toggle source
# File lib/distance.rb, line 94 def >=(other) return false unless other.is_a?(Distance) to_f >= other.to_f end
to_f()
click to toggle source
# File lib/distance.rb, line 41 def to_f distance_in_meters end
to_feet()
click to toggle source
# File lib/distance.rb, line 53 def to_feet (distance_in_meters / Multiplier::FOOT) end
to_inches()
click to toggle source
# File lib/distance.rb, line 49 def to_inches (distance_in_meters / Multiplier::INCH) end
to_kilometers()
click to toggle source
# File lib/distance.rb, line 45 def to_kilometers distance_in_meters / Multiplier::KILOMETER end
to_miles()
click to toggle source
# File lib/distance.rb, line 57 def to_miles (distance_in_meters / Multiplier::MILE) end