Class: Scrape::CLI
- Inherits:
-
Object
- Object
- Scrape::CLI
- Defined in:
- lib/scrape/cli.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(command, argv = "") ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(command, argv = "") ⇒ CLI
Returns a new instance of CLI.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scrape/cli.rb', line 7 def initialize command, argv = "" @command = command @options = {:file => File.join(Dir.pwd, 'Scrapefile'), :ignore_robots_txt => false} opts = OptionParser.new do |opts| opts. = "Scrape #{Scrape::VERSION} - Usage: #{command} [options]" opts.separator "" opts.separator "Specific options:" opts.on "-f", "--scrapefile [FILE]", "Use FILE as scrapefile" do |file| @options[:file] = File. file.strip end opts.on "-i", "--ignore-robots-txt", "Ignore robots.txt" do @options[:ignore_robots_txt] = true end opts.on "-u", "--user-agent [AGENT]", "Change the user agent" do |agent| Scrape.user_agent = agent.strip end opts.on_tail "-h", "--help", "Show this message" do puts opts exit end opts.on_tail "-v", "--version", "Show version" do puts Scrape::VERSION exit end end opts.parse argv @app = Scrape::Application.new [:file], end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/scrape/cli.rb', line 5 def app @app end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/scrape/cli.rb', line 5 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/scrape/cli.rb', line 5 def @options end |
Instance Method Details
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scrape/cli.rb', line 39 def run app.run exit rescue SystemExit, Interrupt puts "" exit rescue Scrape::FileNotFound puts "#{command} aborted!" puts "No Scrapefile found" exit -1 end |