Switch to more object-oriented structure

This commit is contained in:
kojix2
2020-07-29 11:45:03 +09:00
parent 773a086036
commit 7f6f72f48e
2 changed files with 46 additions and 29 deletions

View File

@@ -1,33 +1,5 @@
#!/usr/bin/env ruby
require 'uplot'
require 'unicode_plot'
require 'optparse'
parser = OptionParser.new
subparsers = Hash.new do |_h, k|
warn "no such subcommand: #{k}"
exit 1
end
params = {}
subparsers['hist'] = OptionParser.new.tap do |opt|
opt.on('--nbins VAL') { |v| params[:nbins] = v.to_i }
opt.on('-p') { |v| params[:p] = v }
end
parser.order!(ARGV)
params[:type] = ARGV.shift
subparsers[params[:type]].parse!(ARGV) unless ARGV.empty?
input_lines = readlines.map(&:chomp)
case params[:type]
when 'hist', 'histogram'
series = input_lines.map(&:to_f)
UnicodePlot.histogram(series, nbins: params[:nbins]).render
end
puts input_lines if params[:p]
Uplot::Command.new(ARGV).run