Class: PSGC::Import::ImportRegionProvinces::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



40
41
42
43
# File 'lib/psgc/import/import_region_provinces.rb', line 40

def initialize
  @provinces = []
  @hrefs = {}
end

Instance Attribute Details

#hrefsObject (readonly)

Returns the value of attribute hrefs.



38
39
40
# File 'lib/psgc/import/import_region_provinces.rb', line 38

def hrefs
  @hrefs
end

#provincesObject (readonly)

Returns the value of attribute provinces.



38
39
40
# File 'lib/psgc/import/import_region_provinces.rb', line 38

def provinces
  @provinces
end

Instance Method Details

#parse(html) ⇒ Object



45
46
47
48
49
50
# File 'lib/psgc/import/import_region_provinces.rb', line 45

def parse(html)
  html.css('table').each do |table|
    rows = table/:tr
    parse_row(rows[0]) if rows.count == 1
  end
end

#parse_row(tr) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/psgc/import/import_region_provinces.rb', line 52

def parse_row(tr)
  tds = tr/:td
  if tds.size == 6
    a = tds[0].css('p a')
    if a
      name = a.text
      href = a[0]['href']
      id = tds[1].text[0, 4]
      @provinces << [id, name]
      @hrefs[id] = "province.asp?provCode=#{id}00000"
    end
  end
end