Skip to content

Instantly share code, notes, and snippets.

@advorak
Created August 25, 2014 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save advorak/0a59f244a6a189ca3b37 to your computer and use it in GitHub Desktop.
Save advorak/0a59f244a6a189ca3b37 to your computer and use it in GitHub Desktop.
hash = Hash.new
data = @page.parser.css('tbody.white tr')
headers = data.shift.css('th')[2..-2].collect { |t| t.text.downcase.to_sym }
for row in data
values = row.css('td')[1..-2].collect {|t| t.text.strip.gsub(/(\u00A0|:)/, "").downcase }
key = values.shift.to_sym
hash[key] = Hash.new
headers.each do |header|
hash[key][header] = values.shift.to_i
end
end
hash
table = @page.parser.xpath('//table')[2]
headers = table.css('tr.tHeader th').collect { |t| t.text.downcase.to_sym }.delete_if { |t| t.blank? }
# Remove padding rows
%w(first last).each do |t|
table.css("tr.CBT01bottomBorder td:#{t}").remove
end
hash = Hash.new
headers.each {|t| hash[t] = {}}
table.css("tr.CBT01bottomBorder").each do |tr|
first = tr.css('td:first')
row_header = first.text.gsub(':','').downcase.to_sym
first.remove
tr.css('td').each_with_index do |td,i|
hash[headers[i]][row_header] = td.text.strip.gsub(/\u00a0/,'')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment