Class: PSGC::Import::ImportRegions::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

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

#hrefsObject (readonly)

Returns the value of attribute hrefs.



33
34
35
# File 'lib/psgc/import/import_regions.rb', line 33

def hrefs
  @hrefs
end

#regionsObject (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