Class: Elsmore::Command

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/elsmore/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



9
10
11
# File 'lib/elsmore/command.rb', line 9

def initialize
  self.emitter = Elsmore::Emitter.new
end

Instance Attribute Details

#emitterObject

Returns the value of attribute emitter.



7
8
9
# File 'lib/elsmore/command.rb', line 7

def emitter
  @emitter
end

Instance Method Details

#runObject



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
38
39
40
41
42
# File 'lib/elsmore/command.rb', line 13

def run
  program :name, 'elsmore'
  program :version, Elsmore::VERSION
  program :description, 'A convenient scraper for archiving sites'
  program :help, 'Author', 'Cristiano Betta <[email protected]>'

  global_option('--debug') { emitter.debug! }

  command :snap do |c|
    c.syntax = 'spider <url> [options]'
    c.description = 'Spiders a URL within from the given page, sticking within the original domain'
    c.action do |args, options|
      scraper = Elsmore::Scraper.new(args.first)
      scraper.emitter = emitter
      result = scraper.run

      emitter.newline
      emitter.newline
      emitter.say "Processed"
      emitter.pretty result[:processed]
      emitter.newline
      emitter.say "Could not be processed"
      emitter.pretty result[:invalid]
    end
  end
  alias_command :'go fetch', :'snap'
  default_command :snap

  run!
end