Skip to content

Instantly share code, notes, and snippets.

@advorak advorak/new_code.rb
Created Aug 25, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.