Class: PSGC::Import::ImportMunicipalityBarangays::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

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

#barangaysObject (readonly)

Returns the value of attribute barangays.



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

def barangays
  @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(',', '')
    barangays << [code, name, urban_rural, population]
  end
end