Class: Bipm::Data::Importer::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/bipm/data/importer/fetcher.rb

Overview

Orchestrates a single body's scrape. Picks the strategy declared by the Body, configures VCR/WebMock for the strategy's recording mode, then delegates the actual work. The CLI never touches VCR.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, languages: Language.all, base_dir: "data") ⇒ Fetcher

Returns a new instance of Fetcher.



14
15
16
17
18
# File 'lib/bipm/data/importer/fetcher.rb', line 14

def initialize(body:, languages: Language.all, base_dir: "data")
  @body = body.is_a?(Body) ? body : Bodies.find(body)
  @languages = Array(languages).map { |l| l.is_a?(Language) ? l : Language.find(l) }
  @base_dir = base_dir
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



12
13
14
# File 'lib/bipm/data/importer/fetcher.rb', line 12

def base_dir
  @base_dir
end

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/bipm/data/importer/fetcher.rb', line 12

def body
  @body
end

#languagesObject (readonly)

Returns the value of attribute languages.



12
13
14
# File 'lib/bipm/data/importer/fetcher.rb', line 12

def languages
  @languages
end

Instance Method Details

#call(agent: Mechanize.new) ⇒ Object



20
21
22
23
24
25
# File 'lib/bipm/data/importer/fetcher.rb', line 20

def call(agent: Mechanize.new)
  strategy = strategy_class.new(body: body, base_dir: base_dir, languages: languages)
  with_recording_mode(strategy.recording_mode) do
    strategy.call(agent: agent)
  end
end