Class: YahooStock::Interface::History
- Inherits:
-
YahooStock::Interface
- Object
- YahooStock::Interface
- YahooStock::Interface::History
- Defined in:
- lib/yahoo_stock/interface/history.rb
Overview
DESCRIPTION:
Class to generate the right url and interface with yahoo to get history of a stock
Defined Under Namespace
Classes: HistoryError
Constant Summary
Constants inherited from YahooStock::Interface
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#stock_symbol ⇒ Object
Returns the value of attribute stock_symbol.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from YahooStock::Interface
Instance Method Summary collapse
-
#get ⇒ Object
Get uri content with the help of get method of the super class.
-
#initialize(options) ⇒ History
constructor
The options parameter expects a hash with 4 key value pairs.
-
#uri ⇒ Object
Generate full uri with the help of uri method of the superclass.
Methods inherited from YahooStock::Interface
Constructor Details
#initialize(options) ⇒ History
The options parameter expects a hash with 4 key value pairs
:stock_symbol => ‘goog’, :start_date => Date.today-30, :end_date => Date.today-10, :type => :weekly
The type option accepts :daily, :monthly, :weekly and :dividend values
The type key is optional, if not used then by default uses :daily
and provides daily history for the specified date range
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yahoo_stock/interface/history.rb', line 37 def initialize() @base_url = BASE_URLS[:history] validate_keys() @stock_symbol = [:stock_symbol] @start_date = [:start_date] @end_date = [:end_date] @type = [:type].nil? ? :daily : [:type].to_sym validate_type_values([:type]) if [:type] validate_stock_symbol() validate_start_date() validate_end_date() validate_history_range end |
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
24 25 26 |
# File 'lib/yahoo_stock/interface/history.rb', line 24 def end_date @end_date end |
#start_date ⇒ Object
Returns the value of attribute start_date.
24 25 26 |
# File 'lib/yahoo_stock/interface/history.rb', line 24 def start_date @start_date end |
#stock_symbol ⇒ Object
Returns the value of attribute stock_symbol.
24 25 26 |
# File 'lib/yahoo_stock/interface/history.rb', line 24 def stock_symbol @stock_symbol end |
#type ⇒ Object
Returns the value of attribute type.
24 25 26 |
# File 'lib/yahoo_stock/interface/history.rb', line 24 def type @type end |
Instance Method Details
#get ⇒ Object
Get uri content with the help of get method of the super class
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/yahoo_stock/interface/history.rb', line 99 def get if stock_symbol.nil? || start_date.nil? || end_date.nil? raise HistoryError, 'Cannot send request unless all parameters, ie stock_symbol, start and end date are present' end if !(start_date.is_a?(Date) || end_date.is_a?(Date)) raise HistoryError, 'Start and end date should be of type Date' end uri super() end |
#uri ⇒ Object
Generate full uri with the help of uri method of the superclass
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/yahoo_stock/interface/history.rb', line 84 def uri history_type = case type when :daily then 'd' when :weekly then 'w' when :monthly then 'm' when :dividend then 'v' end @uri_parameters = {:a => sprintf("%02d", start_date.month-1), :b => start_date.day, :c => start_date.year, :d => sprintf("%02d", end_date.month-1), :e => end_date.day, :f => end_date.year, :s => stock_symbol, :g => history_type, :ignore => '.csv'} super() end |