stock_index 0.0.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/stock_index.rb +5 -5
- data/lib/stock_index/attributes.rb +28 -0
- data/lib/stock_index/market.rb +20 -0
- data/lib/stock_index/scrapers/dji_scraper.rb +25 -0
- data/lib/stock_index/stock_index.rb +18 -0
- data/lib/stock_index/version.rb +3 -3
- data/stock_index.gemspec +1 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dad81493b603a0d88be1102058b6ff64191819ce
|
4
|
+
data.tar.gz: da1cee891a8f82639509feb5431056aee53547ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a5f58300a0a1ad4c801c82d6292ce26a08f9ec74033653adf44383a888f800ef2b1965cb8990f29fcb0351acb19434d091e9fdeddf4428089c2922f6800b350
|
7
|
+
data.tar.gz: 7593635fd7b698a9eb7e4b47c8af7b3c2f230322ddd99d05ea122fafdf23574778dd02981136f33f5a865e9a63e3bc176f2c334d8c1c6532afec3a3d96bed69f
|
data/README.md
CHANGED
@@ -23,10 +23,10 @@ There is no a standard for indices symbols, so this gem uses Yahoo Finance symbo
|
|
23
23
|
|
24
24
|
| Symbol | Index Name | Reference page |
|
25
25
|
| ------ | ---------- | -------------- |
|
26
|
-
| ^DJI |
|
26
|
+
| ^DJI | DOW JONES INDUSTRIAL AVERAGE | http://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average |
|
27
27
|
| ^GSPC | S&P 500 | http://en.wikipedia.org/wiki/List_of_S%26P_500_companies |
|
28
28
|
| ^NDX | NASDAQ 100 | https://indexes.nasdaqomx.com/Index/Weighting/NDX |
|
29
|
-
| ^N225 |
|
29
|
+
| ^N225 | NIKKEI 225 | http://indexes.nikkei.co.jp/en/nkave/index/component?idx=nk225 |
|
30
30
|
| ^STOXX50E | EURO STOXX 50 | http://www.stoxx.com/indices/index_information.html?symbol=SX5E |
|
31
31
|
| ^FTSE | FTSE 100 | http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/indices/summary/summary-indices-constituents.html?index=UKX |
|
32
32
|
|
data/lib/stock_index.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'stock_index/version'
|
2
|
+
require 'stock_index/stock_index'
|
3
|
+
require 'stock_index/attributes'
|
4
|
+
require 'stock_index/market'
|
5
|
+
require 'stock_index/scrapers/dji_scraper'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class StockIndex
|
2
|
+
ATTRIBUTES = {
|
3
|
+
'^DJI' => {
|
4
|
+
name: 'DOW JONES INDUSTRIAL AVERAGE',
|
5
|
+
url: 'http://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average'
|
6
|
+
},
|
7
|
+
'^GSPC' => {
|
8
|
+
name: 'S&P 500',
|
9
|
+
url: 'http://en.wikipedia.org/wiki/List_of_S%26P_500_companies'
|
10
|
+
},
|
11
|
+
'^NDX' => {
|
12
|
+
name: 'NASDAQ 100',
|
13
|
+
url: 'https://indexes.nasdaqomx.com/Index/Weighting/NDX'
|
14
|
+
},
|
15
|
+
'^N225' => {
|
16
|
+
name: 'NIKKEI 225',
|
17
|
+
url: 'http://indexes.nikkei.co.jp/en/nkave/index/component?idx=nk225'
|
18
|
+
},
|
19
|
+
'^STOXX50E' => {
|
20
|
+
name: 'EURO STOXX 50',
|
21
|
+
url: 'http://www.stoxx.com/indices/index_information.html?symbol=SX5E'
|
22
|
+
},
|
23
|
+
'^FTSE' => {
|
24
|
+
name: 'FTSE 100',
|
25
|
+
url: 'http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/indices/summary/summary-indices-constituents.html?index=UKX'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class DjiScraper
|
2
|
+
|
3
|
+
def scrape
|
4
|
+
doc = Nokogiri::HTML(open(StockIndex::ATTRIBUTES['^DJI'][:url]))
|
5
|
+
doc.css('table.wikitable.sortable tr').inject([]) do |array, tr|
|
6
|
+
string = "#{market(tr)}:#{symbol(tr)}"
|
7
|
+
array << string unless string == ":"
|
8
|
+
array
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def symbol(tr)
|
15
|
+
symbol_td = tr.css('td')[2]
|
16
|
+
symbol_td ? symbol_td.css('a').text : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def market(tr)
|
20
|
+
market_td = tr.css('td')[1]
|
21
|
+
market = market_td ? market_td.css('a').text : nil
|
22
|
+
StockIndex::Market.new(market).to_iso10383
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/stock_index/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
1
|
+
class StockIndex
|
2
|
+
VERSION = "0.5.0"
|
3
|
+
end
|
data/stock_index.gemspec
CHANGED
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.0
|
4
|
+
version: 0.5.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-11-
|
11
|
+
date: 2014-11-23 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: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Stock Index
|
84
98
|
email:
|
85
99
|
- javier@javiervidal.net
|
@@ -94,6 +108,10 @@ files:
|
|
94
108
|
- Rakefile
|
95
109
|
- csv/US.csv
|
96
110
|
- lib/stock_index.rb
|
111
|
+
- lib/stock_index/attributes.rb
|
112
|
+
- lib/stock_index/market.rb
|
113
|
+
- lib/stock_index/scrapers/dji_scraper.rb
|
114
|
+
- lib/stock_index/stock_index.rb
|
97
115
|
- lib/stock_index/version.rb
|
98
116
|
- stock_index.gemspec
|
99
117
|
homepage: ''
|