Created
August 25, 2014 22:07
-
-
Save advorak/0a59f244a6a189ca3b37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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