2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
20 # Retrieve Quote from Kitco Precious Metals
21 class Smr::Reapers::Kitco
23 QUERY_URL = 'http://www.kitco.com/market/'
25 def initialize(security)
26 raise 'Security object required' unless security.is_a? Security
27 raise 'Security.type=%s not supported by this reaper' % security.type unless Kitco.type_supported? security.type
32 # List of Security#types this reaper can retrieve data for.
33 def Kitco.security_types
38 # tell whether :type can be handled by this reaper.
39 def Kitco.type_supported?(type)
40 Kitco.security_types.include? type.to_sym
44 # Retrieve current Quote for Security
47 page = Nokogiri::HTML(src) do |config|
48 config.strict.noblanks
51 q = Quote.new(:id_security=>@security.id, :exchange=>'World Spot Price')
53 # look for exchange rate to EUR since site shows USD
54 rate = clean_special_chars(
55 page.css('div.exchange_rates span.img_flag_euro').first.parent.parent.next_sibling.css('td.index').text
59 id = case @security.symbol.downcase
60 when 'silver' then 'AG'
62 when 'platinum' then 'PT'
63 when 'palladium' then 'PD'
64 when 'rhodium' then 'RH'
67 q.time_last = Time.strptime(
69 page.css('td#wsp-%s-date' % id).text,
70 page.css('td#wsp-%s-time' % id).text
75 str = clean_special_chars(
76 page.css('td#wsp-%s-bid' % id).text
78 q.last = str.to_f * rate unless str.blank?
80 return (q.last>0 and q.time_last) ? q : false