Class: PSGC::Import::ImportMunicipalityBarangays::Parser
- Inherits:
-
Object
- Object
- PSGC::Import::ImportMunicipalityBarangays::Parser
- Defined in:
- lib/psgc/import/import_municipality_barangays.rb
Instance Attribute Summary collapse
-
#barangays ⇒ Object
readonly
Returns the value of attribute barangays.
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.
43 44 45 |
# File 'lib/psgc/import/import_municipality_barangays.rb', line 43 def initialize @barangays = [] end |
Instance Attribute Details
#barangays ⇒ Object (readonly)
Returns the value of attribute barangays.
41 42 43 |
# File 'lib/psgc/import/import_municipality_barangays.rb', line 41 def @barangays end |
Instance Method Details
#parse(html) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/psgc/import/import_municipality_barangays.rb', line 47 def parse(html) html.css('table').each do |table| rows = table/:tr if rows.count == 1 parse_row(rows[0]) if rows.count == 1 end end end |
#parse_row(tr) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/psgc/import/import_municipality_barangays.rb', line 56 def parse_row(tr) tds = tr/:td if tds.size == 4 name = tds[0].text code = tds[1].text urban_rural = tds[2].text.strip population = tds[3].text.gsub(',', '') << [code, name, urban_rural, population] end end |