nas-yahoo_stock 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -87,4 +87,8 @@ Major changes in the public API. Check the README.rdoc file and individual class
87
87
  * adds cucumber rake task
88
88
 
89
89
  * 1 changes:
90
- * Make sure all tests are run with rspec 2.1.0
90
+ * Make sure all tests are run with rspec 2.1.0
91
+
92
+ === 1.0.7 2010-11-14
93
+
94
+ * Some refactoring after the addition of dividend option to the history
data/README.rdoc CHANGED
@@ -90,7 +90,7 @@ For details : http://nasir.wordpress.com/2009/10/28/ruby-gem-for-finance-data
90
90
 
91
91
  * To find historical data for a stock:
92
92
 
93
- history = YahooStock::History.new(:stock_symbol => 'yhoo', :start_date => Date.today-20, :end_date => Date.today -2)
93
+ history = YahooStock::History.new(:stock_symbol => 'yhoo', :start_date => Date.today-20, :end_date => Date.today-2)
94
94
 
95
95
  * As with regular quotes and symbol lookups, the results can be returned in various formats:
96
96
 
@@ -21,16 +21,16 @@ module YahooStock
21
21
 
22
22
  class HistoryError < RuntimeError ; end
23
23
 
24
- attr_reader :stock_symbol, :start_date, :end_date, :interval
24
+ attr_reader :stock_symbol, :start_date, :end_date, :type
25
25
 
26
26
  # The options parameter expects a hash with 4 key value pairs
27
27
  #
28
28
  # :stock_symbol => 'goog', :start_date => Date.today-30,
29
- # :end_date => Date.today-10, :interval => :weekly
29
+ # :end_date => Date.today-10, :type => :weekly
30
30
  #
31
- # The interval option accepts :daily, :monthly, :weekly and :dividend values
31
+ # The type option accepts :daily, :monthly, :weekly and :dividend values
32
32
  #
33
- # The interval key is optional, if not used then by default uses :daily
33
+ # The type key is optional, if not used then by default uses :daily
34
34
  #
35
35
  # and provides daily history for the specified date range
36
36
  #
@@ -41,9 +41,9 @@ module YahooStock
41
41
  @stock_symbol = options[:stock_symbol]
42
42
  @start_date = options[:start_date]
43
43
  @end_date = options[:end_date]
44
- @interval = options[:interval].nil? ? :daily : options[:interval].to_sym
44
+ @type = options[:type].nil? ? :daily : options[:type].to_sym
45
45
 
46
- validate_interval_values(options[:interval]) if options[:interval]
46
+ validate_type_values(options[:type]) if options[:type]
47
47
  validate_stock_symbol(options)
48
48
  validate_start_date(options)
49
49
  validate_end_date(options)
@@ -74,24 +74,24 @@ module YahooStock
74
74
  @end_date = end_date
75
75
  end
76
76
 
77
- # Set interval to specify whether daily, weekly or monthly histroy required
78
- def interval=(interval)
79
- validate_interval_values(interval)
80
- @interval = interval
77
+ # Set type to specify whether daily, weekly, monthly or dividend history required
78
+ def type=(type)
79
+ validate_type_values(type)
80
+ @type = type
81
81
  end
82
82
 
83
83
  # Generate full uri with the help of uri method of the superclass
84
84
  def uri
85
- frequency = case interval
86
- when :daily then 'd'
87
- when :weekly then 'w'
88
- when :monthly then 'm'
89
- when :dividend then 'v'
90
- end
85
+ history_type = case type
86
+ when :daily then 'd'
87
+ when :weekly then 'w'
88
+ when :monthly then 'm'
89
+ when :dividend then 'v'
90
+ end
91
91
  @uri_parameters = {:a => sprintf("%02d", start_date.month-1), :b => start_date.day,
92
92
  :c => start_date.year, :d => sprintf("%02d", end_date.month-1),
93
93
  :e => end_date.day, :f => end_date.year, :s => stock_symbol,
94
- :g => frequency, :ignore => '.csv'}
94
+ :g => history_type, :ignore => '.csv'}
95
95
  super()
96
96
  end
97
97
 
@@ -109,10 +109,10 @@ module YahooStock
109
109
 
110
110
  private
111
111
 
112
- def validate_interval_values(interval_value=interval)
112
+ def validate_type_values(type_value=type)
113
113
  valid_values = [:daily, :weekly, :monthly, :dividend]
114
- unless valid_values.include?(interval_value)
115
- raise HistoryError, "Allowed values for interval are #{valid_values.join(', ')}"
114
+ unless valid_values.include?(type_value)
115
+ raise HistoryError, "Allowed values for type are #{valid_values.join(', ')}"
116
116
  end
117
117
  end
118
118
 
@@ -174,7 +174,7 @@ module YahooStock
174
174
  end
175
175
 
176
176
  def validate_keys(options)
177
- valid_keys = [:stock_symbol, :start_date, :end_date, :interval]
177
+ valid_keys = [:stock_symbol, :start_date, :end_date, :type]
178
178
  invalid_keys = []
179
179
  options.keys.each{|key| invalid_keys << key unless valid_keys.include?(key) }
180
180
  unless invalid_keys.length.zero?
@@ -84,33 +84,33 @@ describe YahooStock::Interface::History do
84
84
 
85
85
  end
86
86
 
87
- it "should by default set interval to daily if no value provided for it" do
87
+ it "should by default set type to daily if no value provided for it" do
88
88
  @history = YahooStock::Interface::History.new(:stock_symbol => 'd',
89
89
  :start_date => Date.today-7,
90
90
  :end_date => Date.today-1)
91
- @history.interval.should eql(:daily)
91
+ @history.type.should eql(:daily)
92
92
  end
93
93
 
94
94
  it "should raise invalid keys error when an invalid key is passed in the parameter" do
95
95
  lambda { YahooStock::Interface::History.new(:stock_symbol => 'd',
96
96
  :start_date => Date.today-7,
97
- :end_date => Date.today-1, :boom => 1) }.should raise_error(YahooStock::Interface::History::HistoryError, "An invalid key 'boom' is passed in the parameters. Allowed keys are stock_symbol, start_date, end_date, interval")
97
+ :end_date => Date.today-1, :boom => 1) }.should raise_error(YahooStock::Interface::History::HistoryError, "An invalid key 'boom' is passed in the parameters. Allowed keys are stock_symbol, start_date, end_date, type")
98
98
  end
99
99
 
100
- it "should raise error when interval is neither :daily, :weekly, :monthly or :dividend" do
100
+ it "should raise error when type is neither :daily, :weekly, :monthly or :dividend" do
101
101
  lambda { YahooStock::Interface::History.new(:stock_symbol => 'd',
102
102
  :start_date => Date.today-7,
103
103
  :end_date => Date.today-1,
104
- :interval => :yearly)
105
- }.should raise_error(YahooStock::Interface::History::HistoryError, "Allowed values for interval are daily, weekly, monthly, dividend")
104
+ :type => :yearly)
105
+ }.should raise_error(YahooStock::Interface::History::HistoryError, "Allowed values for type are daily, weekly, monthly, dividend")
106
106
 
107
107
  end
108
108
 
109
- it "should not raise error when interval is :daily" do
109
+ it "should not raise error when type is :daily" do
110
110
  lambda { YahooStock::Interface::History.new(:stock_symbol => 'd',
111
111
  :start_date => Date.today-7,
112
112
  :end_date => Date.today-1,
113
- :interval => :daily)
113
+ :type => :daily)
114
114
  }.should_not raise_error
115
115
 
116
116
  end
@@ -170,17 +170,17 @@ describe YahooStock::Interface::History do
170
170
  @history.end_date.should eql(e_date)
171
171
  end
172
172
 
173
- it "should raise error when settin interval other than :daily, :monthly or :weekly" do
174
- lambda { @history.interval = :yearly }.should raise_error(YahooStock::Interface::History::HistoryError)
173
+ it "should raise error when settin type other than :daily, :monthly or :weekly" do
174
+ lambda { @history.type = :yearly }.should raise_error(YahooStock::Interface::History::HistoryError)
175
175
  end
176
176
 
177
- it "should set the interval" do
178
- @history.interval = :daily
179
- @history.interval.should eql(:daily)
177
+ it "should set the type" do
178
+ @history.type = :daily
179
+ @history.type.should eql(:daily)
180
180
  end
181
181
 
182
- it "should set the interval default to daily if not set" do
183
- @history.interval.should eql(:daily)
182
+ it "should set the type default to daily if not set" do
183
+ @history.type.should eql(:daily)
184
184
  end
185
185
  end
186
186
 
@@ -191,8 +191,8 @@ describe YahooStock::Interface::History do
191
191
  :end_date => Date.today-1)
192
192
  end
193
193
 
194
- it "should get the interval to generate url" do
195
- @history.should_receive(:interval)
194
+ it "should get the type to generate url" do
195
+ @history.should_receive(:type)
196
196
  @history.uri
197
197
  end
198
198
 
@@ -251,7 +251,7 @@ describe YahooStock::Interface::History do
251
251
  @history.uri.should =~ /c=#{@history.end_date.year}/
252
252
  end
253
253
 
254
- it "should have parameter 'g' with interval" do
254
+ it "should have parameter 'g' with type" do
255
255
  @history.uri.should =~ /g=d/
256
256
  end
257
257
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nas-yahoo_stock
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 6
10
- version: 1.0.6
9
+ - 7
10
+ version: 1.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nasir Jamal
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-13 00:00:00 +00:00
18
+ date: 2010-11-14 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency