Allowing for query by region and magnitude, too

This commit is contained in:
Dan Buch
2012-02-28 23:35:55 -05:00
parent e84f11dfba
commit 4c2a9ce0b2
2 changed files with 87 additions and 27 deletions

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
require 'pp'
require 'slop'
require File.expand_path('../earthquakes', __FILE__)
@@ -8,12 +9,11 @@ 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 :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.'
on :i, :eqid=, 'Show all available info for earthquake with id.'
end
@@ -24,17 +24,49 @@ def main
return 0
end
if opts.listall_by_region?
earthquakes.all_regions.each { |r| puts r }
if opts.listall_regions?
earthquakes.all_regions.sort.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}"
if opts.listall_magnitudes?
earthquakes.all_magnitudes.sort.each { |m| puts m }
return 0
end
return 0
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
end
return 1
end