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 +5 -1
- data/README.rdoc +1 -1
- data/lib/yahoo_stock/interface/history.rb +21 -21
- data/spec/yahoo_stock/interface/history_spec.rb +18 -18
- metadata +4 -4
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
|
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, :
|
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, :
|
29
|
+
# :end_date => Date.today-10, :type => :weekly
|
30
30
|
#
|
31
|
-
# The
|
31
|
+
# The type option accepts :daily, :monthly, :weekly and :dividend values
|
32
32
|
#
|
33
|
-
# The
|
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
|
-
@
|
44
|
+
@type = options[:type].nil? ? :daily : options[:type].to_sym
|
45
45
|
|
46
|
-
|
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
|
78
|
-
def
|
79
|
-
|
80
|
-
@
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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 =>
|
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
|
112
|
+
def validate_type_values(type_value=type)
|
113
113
|
valid_values = [:daily, :weekly, :monthly, :dividend]
|
114
|
-
unless valid_values.include?(
|
115
|
-
raise HistoryError, "Allowed values for
|
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, :
|
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
|
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.
|
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,
|
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
|
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
|
-
:
|
105
|
-
}.should raise_error(YahooStock::Interface::History::HistoryError, "Allowed values for
|
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
|
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
|
-
:
|
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
|
174
|
-
lambda { @history.
|
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
|
178
|
-
@history.
|
179
|
-
@history.
|
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
|
183
|
-
@history.
|
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
|
195
|
-
@history.should_receive(:
|
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
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
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-
|
18
|
+
date: 2010-11-14 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|