class PSGC::Import::ImportProvinceMunicipalities::Parser
Attributes
cities[R]
hrefs[R]
municipalities[R]
Public Class Methods
new()
click to toggle source
# File lib/psgc/import/import_province_municipalities.rb, line 57 def initialize @cities = [] @municipalities = [] @hrefs = {} end
Public Instance Methods
parse(html)
click to toggle source
# File lib/psgc/import/import_province_municipalities.rb, line 63 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)
click to toggle source
# File lib/psgc/import/import_province_municipalities.rb, line 70 def parse_row(tr) tds = tr/:td if tds.size == 8 a = tds[0].css('p a') if a.count > 0 name = a.text href = a[0]['href'] code = tds[1].text city_class = tds[3].text.gsub("\u00A0", '').strip city = !city_class.empty? h = [code, name] if city @cities << h else @municipalities << h end @hrefs[code] = href end end end