From 68acbb9a0c7967cb90a7e3756fc94fdd8a73d154 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Wed, 29 Jan 2014 19:14:08 +0100
Subject: make use of nlp_ruby, LICENSE
---
avg | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
(limited to 'avg')
diff --git a/avg b/avg
index cc4c0e6..ed31465 100755
--- a/avg
+++ b/avg
@@ -3,28 +3,22 @@
require 'trollop'
-def usage
- STDERR.write "./avg [-r ] < \n"
- exit 1
-end
-usage if not [0,2].include? ARGV.size
-
-opts = Trollop::options do
+cfg = Trollop::options do
+ banner "avg < "
opt :round, "Number of digits after decimal point.", :type => :int, :default => -1
end
-
sum = 0.0
i = 0
-while line=STDIN.gets
- sum += line.strip.to_f
+while line = STDIN.gets
+ sum += line.to_f
i +=1
end
avg = sum/i.to_f
-if opts[:round] >= 0
- puts avg.round opts[:round]
+if cfg[:round] >= 0
+ puts avg.round cfg[:round]
else
puts avg
end
--
cgit v1.2.3