Class: PSGC::Import::ImportRegionProvinces::Parser
- Inherits:
-
Object
- Object
- PSGC::Import::ImportRegionProvinces::Parser
- Defined in:
- lib/psgc/import/import_region_provinces.rb
Instance Attribute Summary collapse
-
#hrefs ⇒ Object
readonly
Returns the value of attribute hrefs.
-
#provinces ⇒ Object
readonly
Returns the value of attribute provinces.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(html) ⇒ Object
- #parse_row(tr) ⇒ Object
Constructor Details
#initialize ⇒ Parser
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
#hrefs ⇒ Object (readonly)
Returns the value of attribute hrefs.
38 39 40 |
# File 'lib/psgc/import/import_region_provinces.rb', line 38 def hrefs @hrefs end |
#provinces ⇒ Object (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 |