Class: Pumi::DataSource::Wikipedia

Inherits:
Object
  • Object
show all
Defined in:
lib/pumi/data_source/wikipedia.rb

Defined Under Namespace

Classes: CambodianCommunesScraper, CambodianDistrictsScraper, CambodianProvincesScraper, ScraperResult, WebScraper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_file:, scraper:) ⇒ Wikipedia

Returns a new instance of Wikipedia.



9
10
11
12
# File 'lib/pumi/data_source/wikipedia.rb', line 9

def initialize(data_file:, scraper:)
  @data_file = data_file
  @scraper = scraper
end

Instance Attribute Details

#data_fileObject (readonly)

Returns the value of attribute data_file.



7
8
9
# File 'lib/pumi/data_source/wikipedia.rb', line 7

def data_file
  @data_file
end

#scraperObject (readonly)

Returns the value of attribute scraper.



7
8
9
# File 'lib/pumi/data_source/wikipedia.rb', line 7

def scraper
  @scraper
end

Instance Method Details

#load_data!(output_dir: "data") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pumi/data_source/wikipedia.rb', line 14

def load_data!(output_dir: "data")
  data.each do |code, attributes|
    location_data = scraped_data.find { |location| location.code == code }
    next unless location_data

    if location_data.wikipedia
      attributes["links"] ||= {}
      attributes["links"]["wikipedia"] = location_data.wikipedia
    end

    attributes["name"]["ungegn"] = location_data.name_ungegn if location_data.name_ungegn
  end

  write_data!(output_dir)
end