Class: ApmexSilverFinanceYtd

Inherits:
FinanceYtd show all
Defined in:
lib/finance-ytd.rb

Instance Attribute Summary

Attributes inherited from FinanceYtd

#css, #css_text, #friendly_name, #symbol, #url, #ytd_return

Instance Method Summary collapse

Methods inherited from FinanceYtd

#to_s

Constructor Details

#initialize(options) ⇒ ApmexSilverFinanceYtd

Returns a new instance of ApmexSilverFinanceYtd.



92
93
94
95
96
97
98
# File 'lib/finance-ytd.rb', line 92

def initialize(options)
  super(options)
  @css = 'table.table-spot-prices > tbody > tr:nth-child(2) > td:nth-child(2) > span'
  @url = 'http://www.apmex.com'
  match()
  calculate()
end

Instance Method Details

#calculateObject



106
107
108
# File 'lib/finance-ytd.rb', line 106

def calculate
  @ytd_return = @price_this_year / @price_last_year - 1.0
end

#matchObject



100
101
102
103
104
# File 'lib/finance-ytd.rb', line 100

def match
  super
  css_text_match = /(\d+\.\d+)/.match(@css_text)
  @price_this_year = css_text_match[1].gsub(',', '').to_f
end