Class: M26::Distance
Constant Summary
Constants included
from Constants
Constants::AUTHOR, Constants::DATE, Constants::EMAIL, Constants::KILOMETERS_PER_MILE, Constants::MILES_PER_KILOMETER, Constants::SECONDS_PER_HOUR, Constants::UOM_KILOMETERS, Constants::UOM_MILES, Constants::UOM_YARDS, Constants::VERSION, Constants::YARDS_PER_KILOMETER, Constants::YARDS_PER_MILE
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(v, um = UOM_MILES) ⇒ Distance
Returns a new instance of Distance.
15
16
17
18
|
# File 'lib/m26_distance.rb', line 15
def initialize(v, um=UOM_MILES)
@value = v.to_f
@uom = um
end
|
Instance Attribute Details
#uom ⇒ Object
Returns the value of attribute uom.
13
14
15
|
# File 'lib/m26_distance.rb', line 13
def uom
@uom
end
|
#value ⇒ Object
Returns the value of attribute value.
13
14
15
|
# File 'lib/m26_distance.rb', line 13
def value
@value
end
|
Instance Method Details
#print_string ⇒ Object
76
77
78
|
# File 'lib/m26_distance.rb', line 76
def print_string
return to_s << " #{get_miles()} #{get_kilometers()} #{get_yards()}"
end
|
#subtract(another_instance) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/m26_distance.rb', line 55
def subtract(another_instance)
if (another_instance != nil)
Distance.new(@value - another_instance.value, @uom)
else
nil
end
end
|
#to_s ⇒ Object
72
73
74
|
# File 'lib/m26_distance.rb', line 72
def to_s
return "Distance: #{@value} #{@uom}"
end
|
#valid? ⇒ Boolean
63
64
65
66
67
68
69
70
|
# File 'lib/m26_distance.rb', line 63
def valid?
return false if @value == nil
return false if @value < 0
return true if @uom == UOM_MILES
return true if @uom == UOM_KILOMETERS
return true if @uom == UOM_YARDS
false
end
|