Prev | Current Page 167 | Next

David Berube

"Practical Reporting with Ruby and Rails"

XML(response_body)
total_price = 0.0
result_count = 0
(hpricot_doc/:SearchResultItem).each do |item| # Iterate through
# each SearchResultItem element.
price_element = (item/:CurrentPrice) # Find the CurrentPrice element
# inside of each SearchResultItem element.
if price_element # If it has a price . . .
total_price = total_price + price_element.first.innerHTML.to_f
#. . . then pull out the
# inside of the element,
# convert it to a float,
# and add it to the total.
# Note that the method is called innerHTML, but
# actually returns the inside of the element.
# This is because Hpricot was originally an HTML
# parsing library.
result_count = result_count + 1
end
end
if result_count > 0
average_price = (total_price/result_count)
else
average_price = nil
end
[result_count, average_price] # Return the number of results and
# average price as an array.
end
end
CHAPTER 6 n TRACKING AUCTIONS WITH EBAY 118
nNote You??™ll need to replace the request token and eBay username with the appropriate values.


Pages:
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
ABBA prezenty Wynajem samochodow Warszawa mieszkania szczecin mieszkanie sosnowiec