box-o-sand/redis-with-ruby/eq-info

44 lines
1.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
require 'slop'
require File.expand_path('../earthquakes', __FILE__)
def main
opts = Slop.parse(:help => true, :strict => true) do
banner "#{File.basename(__FILE__)} [options]"
on :l, :listall, 'List all available earthquake ids.'
on :r, :listall_by_region, 'List available earthquakes by region'
#on :l, :'list-by-region', 'List available earthquakes by region'
#on :L, :'list-by-magnitude', 'List available earthquakes by magnitude'
#on :r, :region=, 'Show earthquakes for region'
#on :m, :magnitude=, 'Show earthquakes of magnitude'
on :i, :eqid=, 'Show all available info for earthquake with id.'
end
earthquakes = Earthquakes.new
if opts.listall?
earthquakes.all_ids.each { |i| puts i }
return 0
end
if opts.listall_by_region?
earthquakes.all_regions.each { |r| puts r }
return 0
end
puts "Earthquake with id of #{opts[:eqid]}"
earthquakes.get_info(opts[:eqid]).each do |key, value|
puts " #{key}: #{value}"
end
return 0
end
if $0 == __FILE__
exit(main)
end