Class: PSGC::Import::ImportRegions

Inherits:
Base
  • Object
show all
Defined in:
lib/psgc/import/import_regions.rb

Overview

Import Region List

Defined Under Namespace

Classes: Parser

Constant Summary

Constants inherited from Base

Base::WEB_FOLDER

Instance Attribute Summary

Attributes inherited from Base

#src

Instance Method Summary collapse

Methods inherited from Base

#fetch

Constructor Details

#initializeImportRegions

Returns a new instance of ImportRegions.



11
12
13
# File 'lib/psgc/import/import_regions.rb', line 11

def initialize
  super 'listreg.asp'
end

Instance Method Details

#parseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/psgc/import/import_regions.rb', line 15

def parse
  parser = Parser.new
  File.open(full_target) do |input|
    parser.parse Nokogiri::HTML(input)
  end
  header = %w(id name)
  CSV.open(PSGC::Region::REGION_DATA, 'w') do |out|
    out << header
    parser.regions.each {|region| out << region }
  end
  parser.hrefs.each do |id, href|
    irp = ImportRegionProvinces.new id, href
    irp.fetch
  end
end