they-yahoo_stock 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/History.txt +98 -0
  2. data/Manifest.txt +37 -0
  3. data/README.rdoc +151 -0
  4. data/Rakefile +12 -0
  5. data/features/history.feature +23 -0
  6. data/features/quotes.feature +23 -0
  7. data/features/script_symbol.feature +23 -0
  8. data/features/step_definitions/history_steps.rb +44 -0
  9. data/features/step_definitions/quotes_steps.rb +45 -0
  10. data/features/step_definitions/script_symbol_steps.rb +40 -0
  11. data/lib/yahoo_stock.rb +21 -0
  12. data/lib/yahoo_stock/base.rb +37 -0
  13. data/lib/yahoo_stock/history.rb +32 -0
  14. data/lib/yahoo_stock/interface.rb +71 -0
  15. data/lib/yahoo_stock/interface/history.rb +187 -0
  16. data/lib/yahoo_stock/interface/quote.rb +287 -0
  17. data/lib/yahoo_stock/interface/scrip_symbol.rb +74 -0
  18. data/lib/yahoo_stock/quote.rb +158 -0
  19. data/lib/yahoo_stock/result.rb +21 -0
  20. data/lib/yahoo_stock/result/array_format.rb +23 -0
  21. data/lib/yahoo_stock/result/hash_format.rb +37 -0
  22. data/lib/yahoo_stock/result/xml_format.rb +37 -0
  23. data/lib/yahoo_stock/scrip_symbol.rb +61 -0
  24. data/spec/spec_helper.rb +4 -0
  25. data/spec/yahoo_stock/base_spec.rb +48 -0
  26. data/spec/yahoo_stock/history_spec.rb +75 -0
  27. data/spec/yahoo_stock/interface/history_spec.rb +317 -0
  28. data/spec/yahoo_stock/interface/quote_spec.rb +414 -0
  29. data/spec/yahoo_stock/interface/scrip_symbol_spec.rb +120 -0
  30. data/spec/yahoo_stock/interface_spec.rb +112 -0
  31. data/spec/yahoo_stock/quote_spec.rb +258 -0
  32. data/spec/yahoo_stock/result/array_format_spec.rb +14 -0
  33. data/spec/yahoo_stock/result/hash_format_spec.rb +65 -0
  34. data/spec/yahoo_stock/result/xml_format_spec.rb +54 -0
  35. data/spec/yahoo_stock/result_spec.rb +33 -0
  36. data/spec/yahoo_stock/scrip_symbol_spec.rb +46 -0
  37. metadata +114 -0
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe YahooStock::Result::ArrayFormat do
4
+
5
+ describe "output" do
6
+
7
+ it "should return an array for each line and each line with an array of csv" do
8
+ string = "asdfsdf,as,f asf s\r\n23,sdf,2332,sdf"
9
+ YahooStock::Result::ArrayFormat.new(string).output.should eql([['asdfsdf','as','f asf s'],['23','sdf' ,'2332', 'sdf']])
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe YahooStock::Result::HashFormat do
4
+ before(:each) do
5
+ @data = 'da,ta'
6
+ @array_format = YahooStock::Result::ArrayFormat.new(@data)
7
+ end
8
+ describe ".new" do
9
+ it "should initialise the Array Format class with data" do
10
+ YahooStock::Result::ArrayFormat.should_receive(:new).and_return(@array_format)
11
+ YahooStock::Result::HashFormat.new(@data){[:key1, :key2]}
12
+ end
13
+
14
+ it "should get the output of the array format" do
15
+ YahooStock::Result::ArrayFormat.stub!(:new).and_return(@array_format)
16
+ @array_format.should_receive(:output)
17
+ YahooStock::Result::HashFormat.new(@data){[:key1, :key2]}
18
+ end
19
+
20
+ it "should yield the block" do
21
+ hash_format = YahooStock::Result::HashFormat.new(@data){['key1', 'key2']}
22
+ hash_format.keys.should eql([:key1, :key2])
23
+ end
24
+ end
25
+
26
+
27
+ describe "output" do
28
+ it "should have the data as a hash with keys key1 and key2" do
29
+ hash_format = YahooStock::Result::HashFormat.new(@data){['key1', 'key2']}
30
+ hash_format.output.should eql([{:key1 => 'da',:key2 => 'ta'}])
31
+ end
32
+
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\nda,ta"
35
+ hash_format = YahooStock::Result::HashFormat.new(data){['key1', 'key2']}
36
+ hash_format.output.should eql([{:key1 => 'da',:key2 => 'ta'},
37
+ {:key1 => 'da',:key2 => 'ta'},
38
+ {:key1 => 'da',:key2 => 'ta'}
39
+ ])
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
50
+ end
51
+
52
+ describe "keys" do
53
+ it "should replace white space characters to underscore in the keys" do
54
+ hash_format = YahooStock::Result::HashFormat.new(@data){['ke y 1', 'k e y 2']}
55
+ hash_format.keys.should eql([:ke_y_1, :k_e_y_2])
56
+ end
57
+
58
+ it "should replace upper case characters to lower case in the keys" do
59
+ hash_format = YahooStock::Result::HashFormat.new(@data){['Key1', 'keY2']}
60
+ hash_format.keys.should eql([:key1, :key2])
61
+ end
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe YahooStock::Result::XmlFormat do
4
+ before(:each) do
5
+ @data = "26.71,65620100,MSFT"
6
+ @attributes = "price,volume,symbol"
7
+ end
8
+
9
+ describe ".new" do
10
+ before(:each) do
11
+ @hashed_format = stub('YahooStock::Result::HashFormat')
12
+ YahooStock::Result::HashFormat.stub!(:new).and_return(@hashed_format)
13
+ end
14
+
15
+ it "should create the new hash object" do
16
+ @hashed_format.stub!(:output)
17
+ YahooStock::Result::HashFormat.should_receive(:new).with(@data){ @attributes }.and_return(@hashed_format)
18
+ YahooStock::Result::XmlFormat.new(@data){@attributes}
19
+ end
20
+
21
+ it "should get the output of the hashed format" do
22
+ @hashed_format.should_receive(:output)
23
+ YahooStock::Result::XmlFormat.new(@data){@attributes}
24
+ end
25
+ end
26
+
27
+ describe "#output" do
28
+ before(:each) do
29
+ @builder = stub('Builder::XmlMarkup')
30
+ Builder::XmlMarkup.stub!(:new).and_return(@builder)
31
+ @xml_format = YahooStock::Result::XmlFormat.new(@data){[:last_trade_price_only, :volume, :last_trade_date]}
32
+ @builder.stub!(:instruct!)
33
+ @builder.stub!(:items)
34
+ @builder.stub!(:item)
35
+ end
36
+
37
+ it "should initialise the builder xml markup object" do
38
+ Builder::XmlMarkup.should_receive(:new).and_return(@builder)
39
+ @xml_format.output
40
+ end
41
+
42
+ it "should create the instruct for the xml" do
43
+ @builder.should_receive(:instruct!)
44
+ @xml_format.output
45
+ end
46
+
47
+ it "should create the root element called items" do
48
+ @builder.should_receive(:items)
49
+ @xml_format.output
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -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
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe YahooStock::ScripSymbol do
4
+ describe ".results" do
5
+ before(:each) do
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)
10
+ end
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')
15
+ end
16
+
17
+ it "find results for each company" do
18
+ @company.should_receive(:results).twice.and_return(@result)
19
+ YahooStock::ScripSymbol.results('company1', 'company2')
20
+ end
21
+
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')
30
+ end
31
+ end
32
+
33
+ describe "data_attributes" do
34
+ before(:each) do
35
+ @symbol = YahooStock::ScripSymbol.new('company name')
36
+ end
37
+ it "should return an array of data attributes" do
38
+ @symbol.data_attributes.should be_instance_of(Array)
39
+ end
40
+
41
+ it "should have following data attributes" do
42
+ @symbol.data_attributes.should include('Symbol', 'Name', 'Last Trade', 'Type', 'Industry Category', 'Exchange')
43
+ end
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: they-yahoo_stock
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nasir Jamal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ requirement: &70291333400560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70291333400560
25
+ description: Yahoo Stock is a Ruby library for extracting information about stocks
26
+ from yahoo finance
27
+ email: nas35_in@yahoo.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files:
31
+ - README.rdoc
32
+ files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/yahoo_stock.rb
38
+ - lib/yahoo_stock/base.rb
39
+ - lib/yahoo_stock/history.rb
40
+ - lib/yahoo_stock/interface.rb
41
+ - lib/yahoo_stock/interface/history.rb
42
+ - lib/yahoo_stock/interface/quote.rb
43
+ - lib/yahoo_stock/interface/scrip_symbol.rb
44
+ - lib/yahoo_stock/quote.rb
45
+ - lib/yahoo_stock/result.rb
46
+ - lib/yahoo_stock/result/array_format.rb
47
+ - lib/yahoo_stock/result/hash_format.rb
48
+ - lib/yahoo_stock/result/xml_format.rb
49
+ - lib/yahoo_stock/scrip_symbol.rb
50
+ - spec/spec_helper.rb
51
+ - spec/yahoo_stock/base_spec.rb
52
+ - spec/yahoo_stock/history_spec.rb
53
+ - spec/yahoo_stock/interface_spec.rb
54
+ - spec/yahoo_stock/interface/history_spec.rb
55
+ - spec/yahoo_stock/interface/quote_spec.rb
56
+ - spec/yahoo_stock/interface/scrip_symbol_spec.rb
57
+ - spec/yahoo_stock/quote_spec.rb
58
+ - spec/yahoo_stock/result_spec.rb
59
+ - spec/yahoo_stock/result/array_format_spec.rb
60
+ - spec/yahoo_stock/result/hash_format_spec.rb
61
+ - spec/yahoo_stock/result/xml_format_spec.rb
62
+ - spec/yahoo_stock/scrip_symbol_spec.rb
63
+ - features/history.feature
64
+ - features/quotes.feature
65
+ - features/script_symbol.feature
66
+ - features/step_definitions/history_steps.rb
67
+ - features/step_definitions/quotes_steps.rb
68
+ - features/step_definitions/script_symbol_steps.rb
69
+ homepage: http://github.com/nas/yahoo_stock
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '1.8'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.10
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Yahoo Stock is a Ruby library for extracting information about stocks from
94
+ yahoo finance.
95
+ test_files:
96
+ - spec/spec_helper.rb
97
+ - spec/yahoo_stock/base_spec.rb
98
+ - spec/yahoo_stock/history_spec.rb
99
+ - spec/yahoo_stock/interface_spec.rb
100
+ - spec/yahoo_stock/interface/history_spec.rb
101
+ - spec/yahoo_stock/interface/quote_spec.rb
102
+ - spec/yahoo_stock/interface/scrip_symbol_spec.rb
103
+ - spec/yahoo_stock/quote_spec.rb
104
+ - spec/yahoo_stock/result_spec.rb
105
+ - spec/yahoo_stock/result/array_format_spec.rb
106
+ - spec/yahoo_stock/result/hash_format_spec.rb
107
+ - spec/yahoo_stock/result/xml_format_spec.rb
108
+ - spec/yahoo_stock/scrip_symbol_spec.rb
109
+ - features/history.feature
110
+ - features/quotes.feature
111
+ - features/script_symbol.feature
112
+ - features/step_definitions/history_steps.rb
113
+ - features/step_definitions/quotes_steps.rb
114
+ - features/step_definitions/script_symbol_steps.rb