nas-yahoo_stock 1.0.7 → 1.0.8
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 +8 -0
- data/lib/yahoo_stock.rb +1 -0
- data/lib/yahoo_stock/result/array_format.rb +1 -5
- data/spec/yahoo_stock/result/array_format_spec.rb +2 -26
- data/spec/yahoo_stock/result/hash_format_spec.rb +10 -1
- metadata +4 -21
data/History.txt
CHANGED
@@ -91,4 +91,8 @@ Major changes in the public API. Check the README.rdoc file and individual class
|
|
91
91
|
|
92
92
|
=== 1.0.7 2010-11-14
|
93
93
|
|
94
|
-
* Some refactoring after the addition of dividend option to the history
|
94
|
+
* Some refactoring after the addition of dividend option to the history
|
95
|
+
|
96
|
+
=== 1.0.8 2011-05-25
|
97
|
+
|
98
|
+
* Parse csv data correctly using CSV gem instead to reinventing the wheel
|
data/README.rdoc
CHANGED
@@ -100,6 +100,13 @@ For details : http://nasir.wordpress.com/2009/10/28/ruby-gem-for-finance-data
|
|
100
100
|
history.results(:to_xml).output
|
101
101
|
history.results.store('filename')
|
102
102
|
|
103
|
+
* History results include 7 values for each day, i.e. date itself, Open, High, Low, Close, Volume and Adj.
|
104
|
+
|
105
|
+
* To get comma separated values with line breaks including header use:
|
106
|
+
|
107
|
+
history.values_with_header
|
108
|
+
(writing this to a file will give a CSV)
|
109
|
+
|
103
110
|
==Docs
|
104
111
|
|
105
112
|
http://rdoc.info/projects/nas/yahoo_stock
|
@@ -115,6 +122,7 @@ Cucumber Test html output is logged in log/features.html
|
|
115
122
|
==Thanks
|
116
123
|
|
117
124
|
* Thanks to {Ryan Sandridge}[http://github.com/dissolved] for adding the dividend query option.
|
125
|
+
* Thanks to {Justin Campbell} [https://github.com/JustinCampbell] for refactoring CSV parsing.
|
118
126
|
|
119
127
|
|
120
128
|
== LICENSE:
|
data/lib/yahoo_stock.rb
CHANGED
@@ -2,6 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
require 'date'
|
5
|
+
require 'csv'
|
5
6
|
require 'yahoo_stock/base.rb'
|
6
7
|
require 'yahoo_stock/interface.rb'
|
7
8
|
require 'yahoo_stock/history.rb'
|
@@ -15,11 +15,7 @@ module YahooStock
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def output
|
18
|
-
|
19
|
-
val = @data.gsub(/\"/,'').split(/\r\n|\n/)
|
20
|
-
new_val = []
|
21
|
-
val.each {|v| new_val << v.split(',')}
|
22
|
-
return new_val
|
18
|
+
CSV.parse @data
|
23
19
|
end
|
24
20
|
|
25
21
|
end
|
@@ -3,36 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe YahooStock::Result::ArrayFormat do
|
4
4
|
|
5
5
|
describe "output" do
|
6
|
-
before(:each) do
|
7
|
-
@data = "asdf\"sdf,as,f\" asf s"
|
8
|
-
@array_format = YahooStock::Result::ArrayFormat.new(@data)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should remove all double quotes from the data string" do
|
12
|
-
@data.should_receive(:gsub).with(/\"/,'').and_return('a string')
|
13
|
-
@array_format.output
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should create array element for each line by splitting it for the line break" do
|
17
|
-
string = "asdfsdf,as,f asf s"
|
18
|
-
@data.stub!(:gsub).and_return(string)
|
19
|
-
string.should_receive(:split).with(/\r\n|\n/).and_return([])
|
20
|
-
@array_format.output
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should create a sub array for each line by splitting them for each comma" do
|
24
|
-
string = "asdfsdf,as,f asf s"
|
25
|
-
@data.stub!(:gsub).and_return(string)
|
26
|
-
string.stub!(:split).with(/\r\n|\n/).and_return([string])
|
27
|
-
string.should_receive(:split).with(',').and_return([])
|
28
|
-
@array_format.output
|
29
|
-
end
|
30
6
|
|
31
7
|
it "should return an array for each line and each line with an array of csv" do
|
32
8
|
string = "asdfsdf,as,f asf s\r\n23,sdf,2332,sdf"
|
33
|
-
|
34
|
-
@array_format.output.should eql([['asdfsdf','as','f asf s'],['23','sdf' ,'2332', 'sdf']])
|
9
|
+
YahooStock::Result::ArrayFormat.new(string).output.should eql([['asdfsdf','as','f asf s'],['23','sdf' ,'2332', 'sdf']])
|
35
10
|
end
|
11
|
+
|
36
12
|
end
|
37
13
|
|
38
14
|
end
|
@@ -31,13 +31,22 @@ describe YahooStock::Result::HashFormat do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should have the data as an array of hashes with the same keys key1 and key2" do
|
34
|
-
data = "da,ta\nda,ta\
|
34
|
+
data = "da,ta\nda,ta\nda,ta"
|
35
35
|
hash_format = YahooStock::Result::HashFormat.new(data){['key1', 'key2']}
|
36
36
|
hash_format.output.should eql([{:key1 => 'da',:key2 => 'ta'},
|
37
37
|
{:key1 => 'da',:key2 => 'ta'},
|
38
38
|
{:key1 => 'da',:key2 => 'ta'}
|
39
39
|
])
|
40
40
|
end
|
41
|
+
|
42
|
+
it "should properly parse data with commas" do
|
43
|
+
data = "da,\"t,a\"\nda,\"t,a\"\nda,\"t,a\""
|
44
|
+
hash_format = YahooStock::Result::HashFormat.new(data){['key1', 'key2']}
|
45
|
+
hash_format.output.should eql([{:key1 => 'da',:key2 => 't,a'},
|
46
|
+
{:key1 => 'da',:key2 => 't,a'},
|
47
|
+
{:key1 => 'da',:key2 => 't,a'}
|
48
|
+
])
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
describe "keys" do
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nas-yahoo_stock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 1.0.7
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.8
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Nasir Jamal
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-05-25 00:00:00 +01:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 1
|
33
|
-
- 2
|
34
24
|
version: 2.1.2
|
35
25
|
type: :runtime
|
36
26
|
version_requirements: *id001
|
@@ -93,24 +83,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
83
|
requirements:
|
94
84
|
- - ">="
|
95
85
|
- !ruby/object:Gem::Version
|
96
|
-
hash: 31
|
97
|
-
segments:
|
98
|
-
- 1
|
99
|
-
- 8
|
100
86
|
version: "1.8"
|
101
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
88
|
none: false
|
103
89
|
requirements:
|
104
90
|
- - ">="
|
105
91
|
- !ruby/object:Gem::Version
|
106
|
-
hash: 3
|
107
|
-
segments:
|
108
|
-
- 0
|
109
92
|
version: "0"
|
110
93
|
requirements: []
|
111
94
|
|
112
95
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.
|
96
|
+
rubygems_version: 1.6.2
|
114
97
|
signing_key:
|
115
98
|
specification_version: 2
|
116
99
|
summary: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance.
|