nas-yahoo_stock 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -1
- data/Manifest.txt +20 -4
- data/README.rdoc +62 -6
- data/lib/yahoo_stock/base.rb +37 -0
- data/lib/yahoo_stock/history.rb +13 -167
- data/lib/yahoo_stock/interface/history.rb +186 -0
- data/lib/yahoo_stock/interface/quote.rb +287 -0
- data/lib/yahoo_stock/interface/scrip_symbol.rb +74 -0
- data/lib/yahoo_stock/interface.rb +45 -217
- data/lib/yahoo_stock/quote.rb +13 -18
- data/lib/yahoo_stock/result/array_format.rb +27 -0
- data/lib/yahoo_stock/result/hash_format.rb +37 -0
- data/lib/yahoo_stock/result.rb +21 -0
- data/lib/yahoo_stock/scrip_symbol.rb +18 -56
- data/lib/yahoo_stock.rb +10 -3
- data/spec/yahoo_stock/base_spec.rb +48 -0
- data/spec/yahoo_stock/history_spec.rb +38 -153
- data/spec/yahoo_stock/interface/history_spec.rb +317 -0
- data/spec/yahoo_stock/interface/quote_spec.rb +414 -0
- data/spec/yahoo_stock/interface/scrip_symbol_spec.rb +120 -0
- data/spec/yahoo_stock/interface_spec.rb +73 -236
- data/spec/yahoo_stock/quote_spec.rb +27 -86
- data/spec/yahoo_stock/result/array_format_spec.rb +38 -0
- data/spec/yahoo_stock/result/hash_format_spec.rb +68 -0
- data/spec/yahoo_stock/result_spec.rb +33 -0
- data/spec/yahoo_stock/scrip_symbol_spec.rb +26 -91
- metadata +31 -37
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe YahooStock::Result do
|
4
|
+
before(:each) do
|
5
|
+
@string_result = 'some string result'
|
6
|
+
@result = YahooStock::Result.new(@string_result)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "output" do
|
10
|
+
it "should return the string" do
|
11
|
+
@result.output.should eql(@string_result)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not call the output method if the parameter passed is string" do
|
15
|
+
@string_result.should_receive(:output).never
|
16
|
+
@result.output
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should call the output method if the parameter passed is not string" do
|
20
|
+
other_result_obj = YahooStock::Result::ArrayFormat.new(@string_result)
|
21
|
+
other_result_obj.should_receive(:output)
|
22
|
+
result = YahooStock::Result.new(other_result_obj)
|
23
|
+
result.output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "store" do
|
28
|
+
it "should open a file to append the output" do
|
29
|
+
File.should_receive(:open).with('filename', 'a')
|
30
|
+
@result.store('filename')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,111 +1,46 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe YahooStock::ScripSymbol do
|
4
|
-
|
5
|
-
describe "find" do
|
4
|
+
describe ".results" do
|
6
5
|
before(:each) do
|
7
|
-
@
|
6
|
+
@company = stub('ScripSymbol')
|
7
|
+
@result = YahooStock::Result.new('cst')
|
8
|
+
YahooStock::ScripSymbol.stub!(:new).and_return(@company)
|
9
|
+
@company.stub!(:results).and_return(@result)
|
8
10
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
it "should create ScripSymbol instance for each company name" do
|
12
|
+
YahooStock::ScripSymbol.should_receive(:new).with('company1').and_return(@company)
|
13
|
+
YahooStock::ScripSymbol.should_receive(:new).with('company2').and_return(@company)
|
14
|
+
YahooStock::ScripSymbol.results('company1', 'company2')
|
13
15
|
end
|
14
16
|
|
15
|
-
it "
|
16
|
-
|
17
|
-
|
18
|
-
res.should_receive(:split).with(/\<\/tr>/).and_return([])
|
19
|
-
@script_symbol.find
|
17
|
+
it "find results for each company" do
|
18
|
+
@company.should_receive(:results).twice.and_return(@result)
|
19
|
+
YahooStock::ScripSymbol.results('company1', 'company2')
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should
|
23
|
-
|
24
|
-
@
|
22
|
+
it "should concatenate the results of all company names and then initialize the YahooStock::Result object" do
|
23
|
+
company2 = stub('ScripSymbol')
|
24
|
+
@result2 = YahooStock::Result.new('qwe')
|
25
|
+
company2.stub!(:results).and_return(@result2)
|
26
|
+
YahooStock::ScripSymbol.stub!(:new).with('company1').and_return(@company)
|
27
|
+
YahooStock::ScripSymbol.stub!(:new).with('company2').and_return(company2)
|
28
|
+
YahooStock::Result.should_receive(:new).with("cst\nqwe\n")
|
29
|
+
YahooStock::ScripSymbol.results('company1', 'company2')
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
28
|
-
describe "
|
33
|
+
describe "data_attributes" do
|
29
34
|
before(:each) do
|
30
|
-
@symbol =
|
31
|
-
@script_symbol = YahooStock::ScripSymbol.stub!(:new).and_return(@symbol)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should find scrip symbol for one company" do
|
35
|
-
@symbol.should_receive(:find).once.and_return([])
|
36
|
-
YahooStock::ScripSymbol.print_options('company1')
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should find scrip symbols for two companies" do
|
40
|
-
@symbol.should_receive(:find).twice.and_return([])
|
41
|
-
YahooStock::ScripSymbol.print_options('company1', 'company2')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return nil" do
|
45
|
-
@symbol.should_receive(:find).and_return([])
|
46
|
-
YahooStock::ScripSymbol.print_options('company1').should eql(nil)
|
35
|
+
@symbol = YahooStock::ScripSymbol.new('company name')
|
47
36
|
end
|
48
|
-
|
49
|
-
|
50
|
-
scrip = ['name','stock']
|
51
|
-
@symbol.stub!(:find).and_return([scrip])
|
52
|
-
YahooStock::ScripSymbol.should_receive(:p).with(scrip).twice
|
53
|
-
YahooStock::ScripSymbol.print_options('company1','company2')
|
37
|
+
it "should return an array of data attributes" do
|
38
|
+
@symbol.data_attributes.should be_instance_of(Array)
|
54
39
|
end
|
55
40
|
|
56
|
-
it "should
|
57
|
-
|
58
|
-
@symbol.stub!(:find).and_return([scrip,scrip])
|
59
|
-
YahooStock::ScripSymbol.should_receive(:p).with(scrip).exactly(4)
|
60
|
-
YahooStock::ScripSymbol.print_options('company1','company2')
|
41
|
+
it "should have following data attributes" do
|
42
|
+
@symbol.data_attributes.should include('Symbol', 'Name', 'Last Trade', 'Type', 'Industry Category', 'Exchange')
|
61
43
|
end
|
62
44
|
end
|
63
|
-
|
64
|
-
describe ".save_options_to_file" do
|
65
|
-
before(:each) do
|
66
|
-
@symbol = stub(YahooStock::ScripSymbol)
|
67
|
-
@script_symbol = YahooStock::ScripSymbol.stub!(:new).and_return(@symbol)
|
68
|
-
@file = stub(File)
|
69
|
-
@file_name = 'file_name'
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should create or open a file with file name parameter and appends to it" do
|
73
|
-
File.should_receive(:open).with(@file_name, 'a')
|
74
|
-
YahooStock::ScripSymbol.save_options_to_file('file_name', 'company1')
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should find scrip symbol for one company" do
|
78
|
-
@symbol.should_receive(:find).once.and_return([])
|
79
|
-
YahooStock::ScripSymbol.save_options_to_file(@file_name,'company1')
|
80
|
-
end
|
81
45
|
|
82
|
-
it "should find scrip symbols for two companies" do
|
83
|
-
@symbol.should_receive(:find).twice.and_return([])
|
84
|
-
YahooStock::ScripSymbol.save_options_to_file(@file_name, 'company1','company2')
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should have one option for each company in the file" do
|
88
|
-
scrip = ['name','stock']
|
89
|
-
@symbol.stub!(:find).and_return([scrip])
|
90
|
-
YahooStock::ScripSymbol.save_options_to_file(@file_name, 'company1','company2')
|
91
|
-
file_data.should eql(["name, stock\n", "name, stock\n"])
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should have two option for each company in the file" do
|
95
|
-
scrip = ['name','stock']
|
96
|
-
@symbol.stub!(:find).and_return([scrip, scrip])
|
97
|
-
YahooStock::ScripSymbol.save_options_to_file(@file_name, 'company1','company2')
|
98
|
-
file_data.should eql(["name, stock\n", "name, stock\n", "name, stock\n", "name, stock\n"])
|
99
|
-
end
|
100
|
-
|
101
|
-
def file_data
|
102
|
-
File.open(@file_name, 'r') { |f| return f.readlines }
|
103
|
-
end
|
104
|
-
|
105
|
-
after(:each) do
|
106
|
-
File.delete(@file_name) if File.exists? @file_name
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nas-yahoo_stock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nasir Jamal
|
@@ -9,29 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-04 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: mime-types
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "1.15"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: diff-lcs
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.2
|
34
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
35
16
|
description: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance
|
36
17
|
email: nas35_in@yahoo.com
|
37
18
|
executables: []
|
@@ -42,25 +23,27 @@ extra_rdoc_files:
|
|
42
23
|
- README.rdoc
|
43
24
|
files:
|
44
25
|
- History.txt
|
45
|
-
- README.rdoc
|
46
26
|
- Manifest.txt
|
27
|
+
- README.rdoc
|
47
28
|
- Rakefile
|
48
29
|
- lib/yahoo_stock.rb
|
49
|
-
- lib/yahoo_stock/
|
30
|
+
- lib/yahoo_stock/base.rb
|
31
|
+
- lib/yahoo_stock/history.rb
|
50
32
|
- lib/yahoo_stock/interface.rb
|
33
|
+
- lib/yahoo_stock/interface/history.rb
|
34
|
+
- lib/yahoo_stock/interface/quote.rb
|
35
|
+
- lib/yahoo_stock/interface/scrip_symbol.rb
|
36
|
+
- lib/yahoo_stock/quote.rb
|
37
|
+
- lib/yahoo_stock/result.rb
|
38
|
+
- lib/yahoo_stock/result/array_format.rb
|
39
|
+
- lib/yahoo_stock/result/hash_format.rb
|
51
40
|
- lib/yahoo_stock/scrip_symbol.rb
|
52
|
-
- lib/yahoo_stock/history.rb
|
53
|
-
- spec/spec_helper.rb
|
54
|
-
- spec/yahoo_stock/quote_spec.rb
|
55
|
-
- spec/yahoo_stock/interface_spec.rb
|
56
|
-
- spec/yahoo_stock/scrip_symbol_spec.rb
|
57
|
-
- spec/yahoo_stock/history_spec.rb
|
58
41
|
has_rdoc: true
|
59
42
|
homepage: http://github.com/nas/yahoo_stock
|
60
|
-
licenses:
|
43
|
+
licenses: []
|
44
|
+
|
61
45
|
post_install_message:
|
62
46
|
rdoc_options:
|
63
|
-
- --inline-source
|
64
47
|
- --charset=UTF-8
|
65
48
|
require_paths:
|
66
49
|
- lib
|
@@ -79,9 +62,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
62
|
requirements: []
|
80
63
|
|
81
64
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.3.
|
65
|
+
rubygems_version: 1.3.4
|
83
66
|
signing_key:
|
84
|
-
specification_version:
|
67
|
+
specification_version: 3
|
85
68
|
summary: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance.
|
86
|
-
test_files:
|
87
|
-
|
69
|
+
test_files:
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/yahoo_stock/base_spec.rb
|
72
|
+
- spec/yahoo_stock/history_spec.rb
|
73
|
+
- spec/yahoo_stock/interface_spec.rb
|
74
|
+
- spec/yahoo_stock/interface/history_spec.rb
|
75
|
+
- spec/yahoo_stock/interface/quote_spec.rb
|
76
|
+
- spec/yahoo_stock/interface/scrip_symbol_spec.rb
|
77
|
+
- spec/yahoo_stock/quote_spec.rb
|
78
|
+
- spec/yahoo_stock/result_spec.rb
|
79
|
+
- spec/yahoo_stock/result/array_format_spec.rb
|
80
|
+
- spec/yahoo_stock/result/hash_format_spec.rb
|
81
|
+
- spec/yahoo_stock/scrip_symbol_spec.rb
|