Class: PSGC::Import::ImportRegions::Parser
- Inherits:
-
Object
- Object
- PSGC::Import::ImportRegions::Parser
- Defined in:
- lib/psgc/import/import_regions.rb
Instance Attribute Summary collapse
-
#hrefs ⇒ Object
readonly
Returns the value of attribute hrefs.
-
#regions ⇒ Object
readonly
Returns the value of attribute regions.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(html) ⇒ Object
- #parse_table(table) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
35 36 37 38 |
# File 'lib/psgc/import/import_regions.rb', line 35 def initialize @regions = [] @hrefs = {} end |
Instance Attribute Details
#hrefs ⇒ Object (readonly)
Returns the value of attribute hrefs.
33 34 35 |
# File 'lib/psgc/import/import_regions.rb', line 33 def hrefs @hrefs end |
#regions ⇒ Object (readonly)
Returns the value of attribute regions.
33 34 35 |
# File 'lib/psgc/import/import_regions.rb', line 33 def regions @regions end |
Instance Method Details
#parse(html) ⇒ Object
40 41 42 43 44 |
# File 'lib/psgc/import/import_regions.rb', line 40 def parse(html) html.css('table.table4').each do |table| parse_table(table) end end |
#parse_table(table) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/psgc/import/import_regions.rb', line 46 def parse_table(table) td = table/:td if (td.size == 2) p = td[0]/:p href = (p/:a)[0]['href'] id = href[/=(\d+)$/, 1] name = (p/:strong).text @regions << [id, name] @hrefs[id] = href end end |