From 0aa1e642d1ce0950b1dd34c92d4436be9efee8c0 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 15 May 2017 18:51:42 +0100 Subject: Add support for C/F temperature calculations using hard coded formula --- blaunits.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/blaunits.rb b/blaunits.rb index 13dc2aa..8c08e0f 100755 --- a/blaunits.rb +++ b/blaunits.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby -VERSION = "2.0.2" -BINARY_NAME = "gunits" +VERSION = "2.1.0" +BINARY_NAME = "units" begin args = ARGV.dup @@ -52,6 +52,13 @@ begin puts "Invalid input! Try !convert [amount] [from-unit] to [to-unit] e.g !convert 2 cm to inches" exit end + if from == "F" && to == "C" + temp = (num - 32) / 1.8 + puts "#{num} F = #{temp} C" + elsif from == "C" && to == "F" + temp = (num * 1.8) + 32 + puts "#{num} C = #{temp} F" + else out = %x(#{BINARY_NAME} -t1 #{from} #{to}) outs = out.split(" ") if outs[0] == "Unknown" @@ -72,5 +79,5 @@ begin exit end puts "#{num} #{from} = #{num * Float(out)} #{to}" - -end \ No newline at end of file + end +end -- cgit v1.2.3