Class: PSGC::Import::ImportRegionProvinces
- Defined in:
- lib/psgc/import/import_region_provinces.rb
Overview
Import Region List
Defined Under Namespace
Classes: Parser
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#region_id ⇒ Object
readonly
Returns the value of attribute region_id.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(region_id, src) ⇒ ImportRegionProvinces
constructor
A new instance of ImportRegionProvinces.
- #parse ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(region_id, src) ⇒ ImportRegionProvinces
Returns a new instance of ImportRegionProvinces.
13 14 15 16 |
# File 'lib/psgc/import/import_region_provinces.rb', line 13 def initialize(region_id, src) super(src) @region_id = region_id end |
Instance Attribute Details
#region_id ⇒ Object (readonly)
Returns the value of attribute region_id.
11 12 13 |
# File 'lib/psgc/import/import_region_provinces.rb', line 11 def region_id @region_id end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/psgc/import/import_region_provinces.rb', line 18 def parse parser = Parser.new File.open(full_target) do |input| parser.parse Nokogiri::HTML(input) end dir = File.join(PSGC::DATA_DIR, @region_id) FileUtils.mkdir_p dir header = %w(id name) CSV.open(File.join(dir, 'provinces.csv'), 'w') do |out| out << header parser.provinces.each {|province| out << province } end parser.hrefs.each do |province_id, href| ipm = ImportProvinceMunicipalities.new province_id, href ipm.fetch end end |