I have the following XML doc:
<AccountPerformanceReportColumns>
<Column name="AccountName" />
<Column name="Impressions" />
<Column name="Clicks" />
<Column name="Ctr" />
<Column name="Conversions" />
<Column name="CostPerConversion" />
<Column name="Spend" />
</AccountPerformanceReportColumns>
<Table>
<Row>
<AccountName value="Cleveland" />
<Impressions value="5822" />
<Clicks value="138" />
<Ctr value="2.37" />
<Conversions value="0" />
<CostPerConversion value="" />
<Spend value="238.28" />
</Row>
<Row>
<AccountName value="Denver" />
<Impressions value="8196" />
<Clicks value="123" />
<Ctr value="1.50" />
<Conversions value="0" />
<CostPerConversion value="" />
<Spend value="258.32" />
</Row>
<Row>
<AccountName value="Houston" />
<Impressions value="7218" />
<Clicks value="105" />
<Ctr value="1.45" />
<Conversions value="3" />
<CostPerConversion value="75.88" />
<Spend value="227.63" />
</Row>
<Row>
<AccountName value="LA" />
<Impressions value="72290" />
<Clicks value="713" />
<Ctr value="0.99" />
<Conversions value="0" />
<CostPerConversion value="" />
<Spend value="932.93" />
</Row>
<Row>
<AccountName value="Louisville" />
<Impressions value="2811" />
<Clicks value="68" />
<Ctr value="2.42" />
<Conversions value="0" />
<CostPerConversion value="" />
<Spend value="167.09" />
</Row>
</Table>
I'm trying to parse it with Nokogiri and convert it to a hash so that I can create a DB record for the hash like:
BingRecords.create!(conversions: hash[:conversion],
spend: hash[:spend],
account_name: hash[:account_name],
date: date,
user_id: user.id)
Where something like:
hash[:account_name] => ["Cleveland", "Denver", "Houston", "LA", "Louisville"]
I tried doing something like:
bingstats = doc.xpath("//AccountName", "//Spend", "//Conversions")
That gives me all the data from those tags followed by stats = bingstats.map {|map| map.values}
which returns:
[["Cleveland], ["Denver"], ["Houston"], ["LA"], ["Louisville"], ["238.28"], ["258.32"]
but that doesn't give me the ability to separate those for the separate records.