Class: LigaMagicScraper::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ligamagic_scraper/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
# File 'lib/ligamagic_scraper/cli.rb', line 7

def initialize(argv = ARGV)
  @argv = argv
  @options = default_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ligamagic_scraper/cli.rb', line 5

def options
  @options
end

Instance Method Details

#create_scraperObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ligamagic_scraper/cli.rb', line 18

def create_scraper
  alert_config = build_alert_config
  
  if store_search?
    StoreScraper.new(
      store_domain: options[:store_domain],
      search_term: options[:search],
      max_pages: options[:max_pages],
      browser_mode: options[:browser_mode],
      alert_config: alert_config
    )
  else
    GlobalScraper.new(
      search_term: options[:search],
      browser_mode: options[:browser_mode],
      alert_config: alert_config
    )
  end
end

#parseObject



12
13
14
15
16
# File 'lib/ligamagic_scraper/cli.rb', line 12

def parse
  option_parser.parse!(@argv)
  validate_options
  self
end