2012-02-29 04:35:36 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2012-02-29 04:35:55 +00:00
|
|
|
require 'pp'
|
2012-02-29 04:35:36 +00:00
|
|
|
require 'slop'
|
|
|
|
|
|
|
|
require File.expand_path('../earthquakes', __FILE__)
|
|
|
|
|
|
|
|
|
|
|
|
def main
|
|
|
|
opts = Slop.parse(:help => true, :strict => true) do
|
|
|
|
banner "#{File.basename(__FILE__)} [options]"
|
2012-02-29 04:35:55 +00:00
|
|
|
on :L, :listall, 'List all available earthquake ids.'
|
|
|
|
on :R, :listall_regions, 'List available earthquake regions.'
|
|
|
|
on :M, :listall_magnitudes, 'List available earthquakes magnitudes.'
|
|
|
|
on :r, :region=, 'Show earthquakes for region.'
|
|
|
|
on :m, :magnitude=, 'Show earthquakes of magnitude.'
|
2012-02-29 04:35:36 +00:00
|
|
|
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
|
|
|
|
|
2012-02-29 04:35:55 +00:00
|
|
|
if opts.listall_regions?
|
|
|
|
earthquakes.all_regions.sort.each { |r| puts r }
|
2012-02-29 04:35:36 +00:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2012-02-29 04:35:55 +00:00
|
|
|
if opts.listall_magnitudes?
|
|
|
|
earthquakes.all_magnitudes.sort.each { |m| puts m }
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if opts[:region]
|
|
|
|
puts "Earthquakes in region #{opts[:region]}"
|
|
|
|
|
|
|
|
results = []
|
|
|
|
earthquakes.in_region(opts[:region]).each do |i|
|
|
|
|
results << earthquakes.get_info(i)
|
|
|
|
end
|
|
|
|
|
|
|
|
puts results.to_yaml
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if opts[:magnitude]
|
|
|
|
puts "Earthquakes with magnitude #{opts[:magnitude]}"
|
|
|
|
|
|
|
|
results = []
|
|
|
|
earthquakes.with_magnitude(opts[:magnitude]).each do |i|
|
|
|
|
results << earthquakes.get_info(i)
|
|
|
|
end
|
|
|
|
|
|
|
|
puts results.to_yaml
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if opts[:eqid]
|
|
|
|
puts "Earthquake with id of #{opts[:eqid]}"
|
|
|
|
earthquakes.get_info(opts[:eqid]).each do |key, value|
|
|
|
|
puts " #{key}: #{value}"
|
|
|
|
end
|
|
|
|
return 0
|
2012-02-29 04:35:36 +00:00
|
|
|
end
|
|
|
|
|
2012-02-29 04:35:55 +00:00
|
|
|
return 1
|
2012-02-29 04:35:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if $0 == __FILE__
|
|
|
|
exit(main)
|
|
|
|
end
|