-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric_imperial_conv.rb
91 lines (84 loc) · 2.32 KB
/
metric_imperial_conv.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def mi_converter
puts
puts "Convert from (m)etric to imperial, or (i)mperial to metric?"
operation = gets.chomp.downcase
def measurement
puts
puts "Convert (l)engths, (w)eights or (v)olumes?"
operation = gets.chomp.downcase
case operation
when "l" then :length
when "w" then :weight
when "v" then :volumes
else
error
measurement
end
end
case operation
when "m" then metric_to_imperial(measurement)
when "i" then imperial_to_metric(measurement)
else
error
mi_converter
end
end
def coefficients
{ miles_to_km: 1.609344,
feet_to_metres: 0.3048,
inches_to_cm: 2.54 }
end
def length(direction)
case direction
when :metric_to_imperial
puts "I will convert kilometres, metres and centimetres into miles, feet and inches."
print "Enter number of kilometres: "
kilometres = get_integer
print "Enter number of metres: "
metres = get_integer
print "Enter number of centimetres: "
centimetres = get_integer
puts " That is #{(kilometres / coefficients[:miles_to_km]).round(2)} miles, #{(metres / coefficients[:feet_to_metres]).round(2)} feet, and #{(centimetres / coefficients[:inches_to_cm]).round(2)} inches."
when :imperial_to_metric
puts "I will convert miles, feet and inches into kilometres, metres and centimetres."
print "Enter number of miles: "
miles = get_integer
print "Enter number of feet: "
feet = get_integer
print "Enter number of inches: "
inches = get_integer
puts " That is #{(miles * coefficients[:miles_to_km]).round(2)} kilometres, #{(feet * coefficients[:feet_to_metres]).round(2)} metres, and #{(inches * coefficients[:inches_to_cm]).round(2)} centimetres."
end
end
def metric_to_imperial(measurement)
case measurement
when :length
length(:metric_to_imperial)
pause
when :weight
puts "Coming Soon in Calculator 2.0 - Weight Mode!!!!"
pause
when :volume
puts "Coming Soon in Calculator 2.0 - Volume Mode!!!!"
pause
else
error
pause
end
end
def imperial_to_metric(measurement)
case measurement
when :length
length(:imperial_to_metric)
pause
when :weight
puts "Coming in Calculator 2.0... Weight Mode!!!!"
pause
when :volume
puts "Coming in Calculator 2.0... Weight Mode!!!!"
pause
else
error
pause
end
end