Renaming script, using JSON for data presentation and handling zero-arg run
This commit is contained in:
parent
3ebd72f6ad
commit
293006314b
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'pp'
|
require 'json'
|
||||||
require 'slop'
|
require 'slop'
|
||||||
|
|
||||||
require File.expand_path('../earthquakes', __FILE__)
|
require File.expand_path('../earthquakes', __FILE__)
|
||||||
@ -17,6 +17,11 @@ def main
|
|||||||
on :i, :eqid=, 'Show all available info for earthquake with id.'
|
on :i, :eqid=, 'Show all available info for earthquake with id.'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ARGV.length < 1
|
||||||
|
puts opts
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
earthquakes = Earthquakes.new
|
earthquakes = Earthquakes.new
|
||||||
|
|
||||||
if opts.listall?
|
if opts.listall?
|
||||||
@ -35,34 +40,32 @@ def main
|
|||||||
end
|
end
|
||||||
|
|
||||||
if opts[:region]
|
if opts[:region]
|
||||||
puts "Earthquakes in region #{opts[:region]}"
|
puts "/* Earthquakes in region #{opts[:region]} */"
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
earthquakes.in_region(opts[:region]).each do |i|
|
earthquakes.in_region(opts[:region]).each do |i|
|
||||||
results << earthquakes.get_info(i)
|
results << earthquakes.get_info(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
puts results.to_yaml
|
puts JSON.pretty_generate(results)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:magnitude]
|
if opts[:magnitude]
|
||||||
puts "Earthquakes with magnitude #{opts[:magnitude]}"
|
puts "/* Earthquakes with magnitude #{opts[:magnitude]} */"
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
earthquakes.with_magnitude(opts[:magnitude]).each do |i|
|
earthquakes.with_magnitude(opts[:magnitude]).each do |i|
|
||||||
results << earthquakes.get_info(i)
|
results << earthquakes.get_info(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
puts results.to_yaml
|
puts JSON.pretty_generate(results)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:eqid]
|
if opts[:eqid]
|
||||||
puts "Earthquake with id of #{opts[:eqid]}"
|
puts "/* Earthquake with id of #{opts[:eqid]} */"
|
||||||
earthquakes.get_info(opts[:eqid]).each do |key, value|
|
puts JSON.pretty_generate(earthquakes.get_info(opts[:eqid]))
|
||||||
puts " #{key}: #{value}"
|
|
||||||
end
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user