class EagleClaw::Runner
Attributes
options[RW]
Public Class Methods
new()
click to toggle source
# File lib/eagleclaw/runner.rb, line 10 def initialize @options = OpenStruct.new(:require => [], :format => :json) end
Public Instance Methods
parse!(args = ARGV)
click to toggle source
# File lib/eagleclaw/runner.rb, line 36 def parse!(args = ARGV) parser.parse!(args) end
parser()
click to toggle source
# File lib/eagleclaw/runner.rb, line 14 def parser @parser ||= OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options] ScraperName" # ---- MAIN ---- opts.on('-r', '--require LIBRARY', "Require LIBRARY before loading scrapers") do |lib| options.require << lib end opts.on('-o', '--output FORMAT', "Output data in format FORMAT (default: JSON)") do |format| options.format = format.downcase.to_sym end # ---- TAIL ---- opts.on_tail('-h', '--help', "Show this help message") { puts opts and exit } end end
run!(args = ARGV)
click to toggle source
# File lib/eagleclaw/runner.rb, line 40 def run!(args = ARGV) parse!(args) @options.require.each { |lib| require(lib) } formatter = EagleClaw::Formatters[@options.format] scraper = EagleClaw::Scrapers[args.shift.downcase.to_sym].new scraper.run data, problems = scraper.data, scraper.problems output = formatter.format(data, problems) puts output end