Class: EagleClaw::Runner
- Inherits:
-
Object
- Object
- EagleClaw::Runner
- Defined in:
- lib/eagleclaw/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #parse!(args = ARGV) ⇒ Object
- #parser ⇒ Object
- #run!(args = ARGV) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
10 11 12 |
# File 'lib/eagleclaw/runner.rb', line 10 def initialize @options = OpenStruct.new(:require => [], :format => :json) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/eagleclaw/runner.rb', line 8 def @options end |
Instance Method Details
#parse!(args = ARGV) ⇒ Object
36 37 38 |
# File 'lib/eagleclaw/runner.rb', line 36 def parse!(args = ARGV) parser.parse!(args) end |
#parser ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eagleclaw/runner.rb', line 14 def parser @parser ||= OptionParser.new do |opts| opts. = "Usage: #{$0} [options] ScraperName" # ---- MAIN ---- opts.on('-r', '--require LIBRARY', "Require LIBRARY before loading scrapers") do |lib| .require << lib end opts.on('-o', '--output FORMAT', "Output data in format FORMAT (default: JSON)") do |format| .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) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# 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 |