Class: Convert
- Inherits:
-
Object
- Object
- Convert
- Defined in:
- lib/convert.rb
Instance Method Summary collapse
- #convert_area(inputvalue, from_unit, to_unit) ⇒ Object
- #convert_speed(inputvalue, from_unit, to_unit) ⇒ Object
- #convert_temp(inputvalue, from_unit, to_unit) ⇒ Object
- #convert_weight(inputvalue, from_unit, to_unit) ⇒ Object
Instance Method Details
#convert_area(inputvalue, from_unit, to_unit) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/convert.rb', line 27 def convert_area(inputvalue, from_unit, to_unit) if from_unit =="acre" && to_unit == "hectare" return result = (inputvalue /2.471) elsif from_unit == "hectare" && to_unit == "acre" return result = (inputvalue *2.471) else return "Error matching case for weight conversion" end end |
#convert_speed(inputvalue, from_unit, to_unit) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/convert.rb', line 38 def convert_speed(inputvalue, from_unit, to_unit) if from_unit =="MPH" && to_unit == "KPH" return result = (inputvalue *1.609) elsif from_unit == "KPH" && to_unit == "MPH" return result = (inputvalue /1.609) else return "Error matching case for area conversion" end end |
#convert_temp(inputvalue, from_unit, to_unit) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/convert.rb', line 2 def convert_temp(inputvalue, from_unit, to_unit) #make sure vars are the right data type inputvalue = inputvalue.to_f from_unit = from_unit.to_s to_unit = to_unit.to_s if from_unit =="Celsius" && to_unit == "Farenheit" return result = (inputvalue * 1.8) + 32 elsif from_unit == "Farenheit" && to_unit == "Celsius" return result = (inputvalue - 32) * 5/9 else return "Error matching case for temp conversion" end end |
#convert_weight(inputvalue, from_unit, to_unit) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/convert.rb', line 17 def convert_weight(inputvalue, from_unit, to_unit) if from_unit =="KG" && to_unit == "Pounds" return result = (inputvalue * 2.20) elsif from_unit == "Pounds" && to_unit == "KG" return result = (inputvalue *0.453) else return "Error matching case for weight conversion" end end |