Class: Yahoo::Stock

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo_stock.rb,
lib/yahoo_stock/base.rb,
lib/yahoo_stock/query.rb

Defined Under Namespace

Classes: Query

Constant Summary collapse

BASE_URI =
'http://au.finance.yahoo.com/q?s='

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stock_code) ⇒ Stock

Returns a new instance of Stock.



5
6
7
# File 'lib/yahoo_stock/base.rb', line 5

def initialize(stock_code)
  @code = stock_code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/yahoo_stock/base.rb', line 3

def code
  @code
end

Instance Method Details

#last_tradeObject

Deprecated methods



29
30
31
# File 'lib/yahoo_stock/base.rb', line 29

def last_trade
  get_info.at(".yfnc_tabledata1").inner_text
end

#last_trade_dateObject



23
24
25
26
# File 'lib/yahoo_stock/base.rb', line 23

def last_trade_date
  t = Time.parse last_trade_time
  t.strftime "%d %B %Y"
end

#last_trade_priceObject



9
10
11
# File 'lib/yahoo_stock/base.rb', line 9

def last_trade_price
  sprintf "%0.2f", get_info.at(".yfnc_tabledata1").inner_text.to_f
end

#last_trade_timeObject



33
34
35
# File 'lib/yahoo_stock/base.rb', line 33

def last_trade_time
  get_info.search(".yfnc_tabledata1")[1].inner_text
end

#last_trade_time_newObject



13
14
15
16
17
18
19
20
21
# File 'lib/yahoo_stock/base.rb', line 13

def last_trade_time_new
  # 'close of trade' if time not present
  t = Time.parse last_trade_time
  if [t.hour, t.min, t.sec] == [0,0,0]
    'close of trade'
  else
    "#{t.hour}:#{t.min}"
  end
end