stock_index 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,226 @@
1
+ ---
2
+ - '4151'
3
+ - '4502'
4
+ - '4503'
5
+ - '4506'
6
+ - '4507'
7
+ - '4519'
8
+ - '4523'
9
+ - '4568'
10
+ - '6479'
11
+ - '6501'
12
+ - '6502'
13
+ - '6503'
14
+ - '6504'
15
+ - '6506'
16
+ - '6508'
17
+ - '6674'
18
+ - '6701'
19
+ - '6702'
20
+ - '6703'
21
+ - '6752'
22
+ - '6753'
23
+ - '6758'
24
+ - '6762'
25
+ - '6767'
26
+ - '6770'
27
+ - '6773'
28
+ - '6841'
29
+ - '6857'
30
+ - '6902'
31
+ - '6952'
32
+ - '6954'
33
+ - '6971'
34
+ - '6976'
35
+ - '7735'
36
+ - '7751'
37
+ - '7752'
38
+ - '8035'
39
+ - '7201'
40
+ - '7202'
41
+ - '7203'
42
+ - '7205'
43
+ - '7211'
44
+ - '7261'
45
+ - '7267'
46
+ - '7269'
47
+ - '7270'
48
+ - '4543'
49
+ - '4902'
50
+ - '7731'
51
+ - '7733'
52
+ - '7762'
53
+ - '9412'
54
+ - '9432'
55
+ - '9433'
56
+ - '9437'
57
+ - '9613'
58
+ - '9984'
59
+ - '8303'
60
+ - '8304'
61
+ - '8306'
62
+ - '8308'
63
+ - '8309'
64
+ - '8316'
65
+ - '8331'
66
+ - '8332'
67
+ - '8354'
68
+ - '8355'
69
+ - '8411'
70
+ - '8253'
71
+ - '8601'
72
+ - '8604'
73
+ - '8628'
74
+ - '8630'
75
+ - '8725'
76
+ - '8729'
77
+ - '8750'
78
+ - '8766'
79
+ - '8795'
80
+ - '1332'
81
+ - '1333'
82
+ - '2002'
83
+ - '2269'
84
+ - '2282'
85
+ - '2501'
86
+ - '2502'
87
+ - '2503'
88
+ - '2531'
89
+ - '2801'
90
+ - '2802'
91
+ - '2871'
92
+ - '2914'
93
+ - '3086'
94
+ - '3099'
95
+ - '3382'
96
+ - '8233'
97
+ - '8252'
98
+ - '8267'
99
+ - '8270'
100
+ - '9983'
101
+ - '4324'
102
+ - '4689'
103
+ - '4704'
104
+ - '9602'
105
+ - '9681'
106
+ - '9735'
107
+ - '9766'
108
+ - '1605'
109
+ - '3101'
110
+ - '3103'
111
+ - '3105'
112
+ - '3401'
113
+ - '3402'
114
+ - '3861'
115
+ - '3863'
116
+ - '3865'
117
+ - '3405'
118
+ - '3407'
119
+ - '4004'
120
+ - '4005'
121
+ - '4021'
122
+ - '4041'
123
+ - '4042'
124
+ - '4043'
125
+ - '4061'
126
+ - '4063'
127
+ - '4183'
128
+ - '4188'
129
+ - '4208'
130
+ - '4272'
131
+ - '4452'
132
+ - '4901'
133
+ - '4911'
134
+ - '6988'
135
+ - '5002'
136
+ - '5020'
137
+ - '5101'
138
+ - '5108'
139
+ - '3110'
140
+ - '5201'
141
+ - '5202'
142
+ - '5214'
143
+ - '5232'
144
+ - '5233'
145
+ - '5301'
146
+ - '5332'
147
+ - '5333'
148
+ - '5401'
149
+ - '5406'
150
+ - '5411'
151
+ - '5413'
152
+ - '5541'
153
+ - '3436'
154
+ - '5703'
155
+ - '5706'
156
+ - '5707'
157
+ - '5711'
158
+ - '5713'
159
+ - '5714'
160
+ - '5715'
161
+ - '5801'
162
+ - '5802'
163
+ - '5803'
164
+ - '5901'
165
+ - '2768'
166
+ - '8001'
167
+ - '8002'
168
+ - '8015'
169
+ - '8031'
170
+ - '8053'
171
+ - '8058'
172
+ - '1721'
173
+ - '1801'
174
+ - '1802'
175
+ - '1803'
176
+ - '1812'
177
+ - '1925'
178
+ - '1928'
179
+ - '1963'
180
+ - '5631'
181
+ - '6103'
182
+ - '6113'
183
+ - '6301'
184
+ - '6302'
185
+ - '6305'
186
+ - '6326'
187
+ - '6361'
188
+ - '6366'
189
+ - '6367'
190
+ - '6471'
191
+ - '6472'
192
+ - '6473'
193
+ - '7004'
194
+ - '7011'
195
+ - '7013'
196
+ - '7003'
197
+ - '7012'
198
+ - '7911'
199
+ - '7912'
200
+ - '7951'
201
+ - '3289'
202
+ - '8801'
203
+ - '8802'
204
+ - '8803'
205
+ - '8804'
206
+ - '8830'
207
+ - '9001'
208
+ - '9005'
209
+ - '9007'
210
+ - '9008'
211
+ - '9009'
212
+ - '9020'
213
+ - '9021'
214
+ - '9022'
215
+ - '9062'
216
+ - '9064'
217
+ - '9101'
218
+ - '9104'
219
+ - '9107'
220
+ - '9202'
221
+ - '9301'
222
+ - '9501'
223
+ - '9502'
224
+ - '9503'
225
+ - '9531'
226
+ - '9532'
@@ -0,0 +1,105 @@
1
+ ---
2
+ - FOXA
3
+ - ATVI
4
+ - ADBE
5
+ - AKAM
6
+ - ALXN
7
+ - ALTR
8
+ - AMZN
9
+ - AMGN
10
+ - ADI
11
+ - AAPL
12
+ - AMAT
13
+ - ADSK
14
+ - ADP
15
+ - AVGO
16
+ - BIDU
17
+ - BBBY
18
+ - BIIB
19
+ - BRCM
20
+ - CHRW
21
+ - CA
22
+ - CTRX
23
+ - CELG
24
+ - CERN
25
+ - CHTR
26
+ - CHKP
27
+ - CSCO
28
+ - CTXS
29
+ - CTSH
30
+ - CMCSA
31
+ - COST
32
+ - DTV
33
+ - DISCA
34
+ - DISCK
35
+ - DISH
36
+ - DLTR
37
+ - EBAY
38
+ - EQIX
39
+ - EXPE
40
+ - EXPD
41
+ - ESRX
42
+ - FFIV
43
+ - FB
44
+ - FAST
45
+ - FISV
46
+ - GRMN
47
+ - GILD
48
+ - GOOGL
49
+ - GOOG
50
+ - HSIC
51
+ - ILMN
52
+ - INTC
53
+ - INTU
54
+ - ISRG
55
+ - GMCR
56
+ - KLAC
57
+ - KRFT
58
+ - LBTYA
59
+ - QVCA
60
+ - LMCK
61
+ - LMCA
62
+ - LVNTA
63
+ - LLTC
64
+ - MAR
65
+ - MAT
66
+ - MXIM
67
+ - MU
68
+ - MSFT
69
+ - MDLZ
70
+ - MNST
71
+ - MYL
72
+ - NTAP
73
+ - NFLX
74
+ - NVDA
75
+ - NXPI
76
+ - ORLY
77
+ - PCAR
78
+ - PAYX
79
+ - QCOM
80
+ - REGN
81
+ - ROST
82
+ - SNDK
83
+ - SBAC
84
+ - STX
85
+ - SIAL
86
+ - SIRI
87
+ - SPLS
88
+ - SBUX
89
+ - SRCL
90
+ - SYMC
91
+ - TSLA
92
+ - TXN
93
+ - PCLN
94
+ - TSCO
95
+ - TRIP
96
+ - VRSK
97
+ - VRTX
98
+ - VIAB
99
+ - VIP
100
+ - VOD
101
+ - WDC
102
+ - WFM
103
+ - WYNN
104
+ - XLNX
105
+ - YHOO
data/spec/helper.rb CHANGED
@@ -6,20 +6,65 @@ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCo
6
6
  SimpleCov.start
7
7
 
8
8
  require 'stock_index'
9
+ require 'webmock/rspec'
10
+
11
+ WebMock.disable_net_connect!(allow: 'coveralls.io')
12
+
13
+ RSpec.configure do |config|
14
+ config.before(:each) do
15
+
16
+ stub_request(:get, "http://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average").
17
+ with(:headers => {'Accept' => '*/*'}).
18
+ to_return(:status => 200, :body => fixture_html('dji'), :headers => {})
19
+
20
+ stub_request(:get, "http://en.wikipedia.org/wiki/List_of_S&P_500_companies").
21
+ with(:headers => {'Accept' => '*/*'}).
22
+ to_return(:status => 200, :body => fixture_html('gspc'), :headers => {})
23
+
24
+ stub_request(:get, "http://en.wikipedia.org/wiki/NASDAQ-100").
25
+ with(:headers => {'Accept' => '*/*'}).
26
+ to_return(:status => 200, :body => fixture_html('ndx'), :headers => {})
27
+
28
+ stub_request(:get, "http://indexes.nikkei.co.jp/en/nkave/index/component?idx=nk225").
29
+ with(:headers => {'Accept' => '*/*'}).
30
+ to_return(:status => 200, :body => fixture_html('n225'), :headers => {})
31
+
32
+ stub_request(:get, "http://en.wikipedia.org/wiki/Nikkei_225").
33
+ with(:headers => {'Accept' => '*/*'}).
34
+ to_return(:status => 200, :body => fixture_html('n225_wikipedia'), :headers => {})
35
+
36
+ stub_request(:get, "http://www.sec.gov/cgi-bin/browse-edgar?CIK=CSCO&action=getcompany").
37
+ with(:headers => {'Accept' => '*/*'}).
38
+ to_return(:status => 200, :body => edgar_html, :headers => {})
39
+
40
+ stub_request(:get, "http://www.sec.gov/cgi-bin/browse-edgar?CIK=ZZZZ&action=getcompany").
41
+ with(:headers => {'Accept' => '*/*'}).
42
+ to_return(:status => 200, :body => "", :headers => {})
43
+
44
+ end
45
+ end
9
46
 
10
47
  def fixture_path
11
48
  File.expand_path('../fixtures', __FILE__)
12
49
  end
13
50
 
14
- def fixture(symbol)
15
- File.new(fixture_path + '/' + file(symbol))
51
+ def fixture_yaml(symbol)
52
+ File.new(File.join(fixture_path, 'yaml', yaml_file(symbol)))
16
53
  end
17
54
 
18
- def file(symbol)
55
+ def fixture_html(page)
56
+ File.new(File.join(fixture_path, 'html', "#{page}.html"))
57
+ end
58
+
59
+ def yaml_file(symbol)
19
60
  md = /\^(\w+)/.match(symbol)
20
61
  "#{md[1]}.yaml"
21
62
  end
22
63
 
23
64
  def components_from_fixture(symbol)
24
- YAML::load_file(fixture(symbol))
65
+ YAML::load_file(fixture_yaml(symbol))
66
+ end
67
+
68
+ def edgar_html
69
+ File.new(File.join(fixture_path, 'html', "edgar.html"))
25
70
  end
@@ -5,7 +5,7 @@ describe StockIndex::BsymSearch do
5
5
  context 'searching a symbol in EXCEPTIONS' do
6
6
 
7
7
  it 'returns the component' do
8
- expect(StockIndex::BsymSearch.find('BIDU')).to eq({name: 'BAIDU INC', bbgid: 'BBG000QXWHD1'})
8
+ expect(StockIndex::BsymSearch.find('BIDU', :us)).to eq({name: 'BAIDU INC', bbgid: 'BBG000QXWHD1'})
9
9
  end
10
10
 
11
11
  end
@@ -13,7 +13,7 @@ describe StockIndex::BsymSearch do
13
13
  context 'searching a symbol in the CSV file' do
14
14
 
15
15
  it 'returns the component' do
16
- expect(StockIndex::BsymSearch.find('CSCO')).to eq({:name=>"CISCO SYSTEMS INC", :bbgid=>"BBG000C3J3C9"})
16
+ expect(StockIndex::BsymSearch.find('CSCO', :us)).to eq({:name=>"CISCO SYSTEMS INC", :bbgid=>"BBG000C3J3C9"})
17
17
  end
18
18
 
19
19
  end
@@ -21,7 +21,7 @@ describe StockIndex::BsymSearch do
21
21
  context 'searching a non existent symbol' do
22
22
 
23
23
  it 'returns nil' do
24
- expect(StockIndex::BsymSearch.find('ZZZZ')).to eq(nil)
24
+ expect(StockIndex::BsymSearch.find('ZZZZ', :us)).to eq(nil)
25
25
  end
26
26
 
27
27
  end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ describe StockIndex::Component do
4
+
5
+ it 'returns the value written to the cache' do
6
+ component = StockIndex::Component.new('T', 'test', nil)
7
+ component.cache_write('ZZZZ')
8
+ expect(component.cache_lookup).to eq('ZZZZ')
9
+ end
10
+
11
+ it 'returns the correct attributes with a valid symbol' do
12
+ component = StockIndex::Component.new('CSCO', 'XNAS', nil)
13
+ expect(component.attributes_lookup).to eq({:market=>"XNAS", :symbol=>"CSCO", :name=>"CISCO SYSTEMS INC", :wikipedia=>nil, :cik=>"0000858877", :bbgid=>"BBG000C3J3C9"})
14
+ end
15
+
16
+ it 'returns nil with an invalid symbol' do
17
+ component = StockIndex::Component.new('ZZZZ', 'XNAS', nil)
18
+ expect(component.attributes_lookup).to be_nil
19
+ end
20
+
21
+ end
@@ -9,18 +9,25 @@ describe StockIndex do
9
9
  # How to generate a fixture file
10
10
  #
11
11
  # require 'yaml'
12
- # File.open('spec/fixtures/NDX.yaml', 'w') {|f| f.write StockIndex.new('^NDX').components.to_yaml }
12
+ # File.open('spec/fixtures/DJI.yaml', 'w') {|f| f.write StockIndex.new('^DJI').components.map{ |e| e[:symbol]}.to_yaml }
13
+ # File.open('spec/fixtures/GSPC.yaml', 'w') {|f| f.write StockIndex.new('^GSPC').components.map{ |e| e[:symbol]}.to_yaml }
14
+ # File.open('spec/fixtures/NDX.yaml', 'w') {|f| f.write StockIndex.new('^NDX').components.map{ |e| e[:symbol]}.to_yaml }
15
+ # File.open('spec/fixtures/N225.yaml', 'w') {|f| f.write StockIndex.new('^N225').components.map{ |e| e[:symbol]}.to_yaml }
13
16
 
14
17
  it 'returns components for ^DJI' do
15
- expect(StockIndex.new('^DJI').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^DJI').map{ |e| e[:symbol] })
18
+ expect(StockIndex.new('^DJI').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^DJI'))
16
19
  end
17
20
 
18
21
  it 'returns components for ^GSPC' do
19
- expect(StockIndex.new('^GSPC').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^GSPC').map{ |e| e[:symbol] })
22
+ expect(StockIndex.new('^GSPC').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^GSPC'))
20
23
  end
21
24
 
22
25
  it 'returns components for ^NDX' do
23
- expect(StockIndex.new('^NDX').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^NDX').map{ |e| e[:symbol] })
26
+ expect(StockIndex.new('^NDX').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^NDX'))
27
+ end
28
+
29
+ it 'returns components for ^N225' do
30
+ expect(StockIndex.new('^N225').components.map{ |e| e[:symbol] }).to match_array(components_from_fixture('^N225'))
24
31
  end
25
32
 
26
33
  end
data/stock_index.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "awesome_print"
24
24
  spec.add_development_dependency "rspec"
25
25
  spec.add_development_dependency "simplecov"
26
+ spec.add_development_dependency "webmock"
26
27
  spec.add_development_dependency "coveralls"
27
28
  spec.add_runtime_dependency "nokogiri"
28
29
  spec.add_runtime_dependency "cik"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stock_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Vidal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: coveralls
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -131,12 +145,17 @@ extra_rdoc_files: []
131
145
  files:
132
146
  - ".gitignore"
133
147
  - ".rspec"
148
+ - ".travis.yml"
134
149
  - Gemfile
135
150
  - LICENSE.txt
136
151
  - README.md
137
152
  - Rakefile
153
+ - bsym/JP.csv
138
154
  - bsym/US.csv
139
- - cache/data.pstore
155
+ - cache/XJPX.pstore
156
+ - cache/XNAS.pstore
157
+ - cache/XNYS.pstore
158
+ - cache/test.pstore
140
159
  - lib/stock_index.rb
141
160
  - lib/stock_index/bsym_search.rb
142
161
  - lib/stock_index/component.rb
@@ -146,14 +165,23 @@ files:
146
165
  - lib/stock_index/scrapers/base_scraper.rb
147
166
  - lib/stock_index/scrapers/dji_scraper.rb
148
167
  - lib/stock_index/scrapers/nasdaq_scraper.rb
168
+ - lib/stock_index/scrapers/nikkei_scraper.rb
149
169
  - lib/stock_index/stock_index.rb
150
170
  - lib/stock_index/symbol_parser.rb
151
171
  - lib/stock_index/version.rb
152
- - spec/fixtures/DJI.yaml
153
- - spec/fixtures/GSPC.yaml
154
- - spec/fixtures/NDX.yaml
172
+ - spec/fixtures/html/dji.html
173
+ - spec/fixtures/html/edgar.html
174
+ - spec/fixtures/html/gspc.html
175
+ - spec/fixtures/html/n225.html
176
+ - spec/fixtures/html/n225_wikipedia.html
177
+ - spec/fixtures/html/ndx.html
178
+ - spec/fixtures/yaml/DJI.yaml
179
+ - spec/fixtures/yaml/GSPC.yaml
180
+ - spec/fixtures/yaml/N225.yaml
181
+ - spec/fixtures/yaml/NDX.yaml
155
182
  - spec/helper.rb
156
183
  - spec/stock_index/bsym_search_spec.rb
184
+ - spec/stock_index/component_spec.rb
157
185
  - spec/stock_index/stock_index_spec.rb
158
186
  - spec/stock_index/symbol_parser_spec.rb
159
187
  - stock_index.gemspec
@@ -182,10 +210,18 @@ signing_key:
182
210
  specification_version: 4
183
211
  summary: Stock Index
184
212
  test_files:
185
- - spec/fixtures/DJI.yaml
186
- - spec/fixtures/GSPC.yaml
187
- - spec/fixtures/NDX.yaml
213
+ - spec/fixtures/html/dji.html
214
+ - spec/fixtures/html/edgar.html
215
+ - spec/fixtures/html/gspc.html
216
+ - spec/fixtures/html/n225.html
217
+ - spec/fixtures/html/n225_wikipedia.html
218
+ - spec/fixtures/html/ndx.html
219
+ - spec/fixtures/yaml/DJI.yaml
220
+ - spec/fixtures/yaml/GSPC.yaml
221
+ - spec/fixtures/yaml/N225.yaml
222
+ - spec/fixtures/yaml/NDX.yaml
188
223
  - spec/helper.rb
189
224
  - spec/stock_index/bsym_search_spec.rb
225
+ - spec/stock_index/component_spec.rb
190
226
  - spec/stock_index/stock_index_spec.rb
191
227
  - spec/stock_index/symbol_parser_spec.rb