ticker_fetcher 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/README.rdoc +0 -0
- data/Rakefile +0 -0
- data/lib/ticker_fetcher.rb +6 -1
- data/lib/ticker_fetcher/retriever.rb +12 -29
- data/lib/ticker_fetcher/stock.rb +7 -8
- data/test/amex_test_data.csv +0 -0
- data/test/helper.rb +1 -0
- data/test/nasd_test_data.csv +0 -0
- data/test/nyse_test_data.csv +0 -0
- data/test/test_retriever.rb +1 -7
- data/test/test_stock.rb +15 -15
- data/ticker_fetcher.gemspec +3 -2
- metadata +20 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2000079b6ceaa5d5b2fb89ae9c7010eee305282b
|
4
|
+
data.tar.gz: ef18a6900e7017dd2f0004831bf54cdc9ee30f6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ae6077703907af2c522f9c914d4946d3f93318a8a5568d53a341af3be5c8ee6f5ea67fc76bebfab427a593a360f661dab8b1d1ce074841a38ebc278e76489cf
|
7
|
+
data.tar.gz: cc8ec4ae0e569f9c55f48e540b0f099f394dd6a9644c3f5d33299a8739b77894c8009eccf0c3dbc8f1a0643100602abbb656428afd93af493ed0c0b5b0838c04
|
data/.gitignore
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.rdoc
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/ticker_fetcher.rb
CHANGED
@@ -2,4 +2,9 @@ require 'ticker_fetcher/retriever'
|
|
2
2
|
require 'ticker_fetcher/stock'
|
3
3
|
|
4
4
|
module TickerFetcher
|
5
|
-
|
5
|
+
EXCHANGE_URLS = {
|
6
|
+
'AMEX' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download',
|
7
|
+
'NASD' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download',
|
8
|
+
'NYSE' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download'
|
9
|
+
}
|
10
|
+
end
|
@@ -1,34 +1,21 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'open-uri'
|
3
1
|
require 'csv'
|
2
|
+
require 'open-uri'
|
4
3
|
require 'ticker_fetcher/stock'
|
5
4
|
|
6
5
|
module TickerFetcher
|
7
6
|
class Retriever
|
8
|
-
|
9
|
-
Name = 1
|
10
|
-
LastSale = 2
|
11
|
-
MarketCap = 3
|
12
|
-
IPOYear = 4
|
13
|
-
Sector = 5
|
14
|
-
Industry = 6
|
15
|
-
attr_reader :exchanges, :exchange_urls
|
7
|
+
attr_reader :exchanges
|
16
8
|
|
17
9
|
# Passing an exchange name will retrieve only that exchange. Default is to retrieve all.
|
18
10
|
def initialize
|
19
11
|
@exchanges = {}
|
20
|
-
@exchange_urls = {
|
21
|
-
'AMEX' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=AMEX&render=download',
|
22
|
-
'NASD' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download',
|
23
|
-
'NYSE' => 'http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NYSE&render=download'
|
24
|
-
}
|
25
12
|
end
|
26
13
|
|
27
14
|
def run(exchange=:all)
|
28
15
|
if exchange == :all
|
29
|
-
|
16
|
+
EXCHANGE_URLS.each { |exchange, url| @exchanges[exchange] = parse_exchange(exchange, url) }
|
30
17
|
else
|
31
|
-
@exchanges[exchange] = parse_exchange(exchange,
|
18
|
+
@exchanges[exchange] = parse_exchange(exchange, EXCHANGE_URLS[exchange])
|
32
19
|
end
|
33
20
|
end
|
34
21
|
|
@@ -44,40 +31,36 @@ module TickerFetcher
|
|
44
31
|
private
|
45
32
|
|
46
33
|
def parse_csv(data)
|
47
|
-
CSV.parse(data, :
|
48
|
-
stocks << TickerFetcher::Stock.new(
|
34
|
+
CSV.parse(data, headers: true).inject([]) do |stocks, row|
|
35
|
+
stocks << TickerFetcher::Stock.new(row)
|
49
36
|
end
|
50
37
|
end
|
51
38
|
|
52
39
|
def name(row)
|
53
|
-
row[Name]
|
40
|
+
row['Name']
|
54
41
|
end
|
55
42
|
|
56
43
|
def ticker(row)
|
57
|
-
ticker = row[Symbol].strip.gsub('"', '')
|
44
|
+
ticker = row['Symbol'].strip.gsub('"', '')
|
58
45
|
unless(ticker.nil? || ticker.empty?)
|
59
46
|
ticker = ticker =~ /\W/ ? ticker.gsub('/', '.').gsub('^', '-') : ticker
|
60
47
|
end
|
61
48
|
end
|
62
49
|
|
63
50
|
def last_sale(row)
|
64
|
-
row[LastSale]
|
51
|
+
row['LastSale']
|
65
52
|
end
|
66
53
|
|
67
54
|
def market_cap(row)
|
68
|
-
row[MarketCap]
|
69
|
-
end
|
70
|
-
|
71
|
-
def ipo_year(row)
|
72
|
-
row[IPOYear]
|
55
|
+
row['MarketCap']
|
73
56
|
end
|
74
57
|
|
75
58
|
def sector(row)
|
76
|
-
row[Sector]
|
59
|
+
row['Sector']
|
77
60
|
end
|
78
61
|
|
79
62
|
def industry(row)
|
80
|
-
row[Industry]
|
63
|
+
row['Industry']
|
81
64
|
end
|
82
65
|
end
|
83
66
|
end
|
data/lib/ticker_fetcher/stock.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module TickerFetcher
|
2
2
|
class Stock
|
3
|
-
attr_reader :symbol, :name, :last_sale, :market_cap, :
|
3
|
+
attr_reader :symbol, :name, :last_sale, :market_cap, :sector, :industry
|
4
4
|
|
5
5
|
def initialize(data)
|
6
|
-
@symbol = data[
|
7
|
-
@name = data[
|
8
|
-
@last_sale = data[
|
9
|
-
@market_cap = data[
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@industry = data[TickerFetcher::Retriever::Industry]
|
6
|
+
@symbol = data['Symbol']
|
7
|
+
@name = data['Name']
|
8
|
+
@last_sale = data['LastSale']
|
9
|
+
@market_cap = data['MarketCap']
|
10
|
+
@sector = data['Sector']
|
11
|
+
@industry = data['Industry']
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
data/test/amex_test_data.csv
CHANGED
File without changes
|
data/test/helper.rb
CHANGED
data/test/nasd_test_data.csv
CHANGED
File without changes
|
data/test/nyse_test_data.csv
CHANGED
File without changes
|
data/test/test_retriever.rb
CHANGED
@@ -4,7 +4,7 @@ require 'ticker_fetcher/retriever'
|
|
4
4
|
class TestRetriever < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@retriever = TickerFetcher::Retriever.new
|
7
|
-
|
7
|
+
TickerFetcher::EXCHANGE_URLS.each do |exchange, url|
|
8
8
|
FakeWeb.register_uri(
|
9
9
|
:get,
|
10
10
|
url,
|
@@ -58,12 +58,6 @@ class TestRetriever < Test::Unit::TestCase
|
|
58
58
|
assert_equal('85473000', @retriever.exchanges['NYSE'].last.market_cap)
|
59
59
|
end
|
60
60
|
|
61
|
-
def test_retrieve_with_one_exchange_returns_a_ticker_fetcher_with_correct_ipo_year
|
62
|
-
@retriever.run('NYSE')
|
63
|
-
assert_equal('1999', @retriever.exchanges['NYSE'].first.ipo_year)
|
64
|
-
assert_equal('2015', @retriever.exchanges['NYSE'].last.ipo_year)
|
65
|
-
end
|
66
|
-
|
67
61
|
def test_retrieve_with_one_exchange_returns_a_ticker_fetcher_with_correct_sector
|
68
62
|
@retriever.run('NYSE')
|
69
63
|
assert_equal('Consumer Services', @retriever.exchanges['NYSE'].first.sector)
|
data/test/test_stock.rb
CHANGED
@@ -3,23 +3,23 @@ require 'ticker_fetcher/stock'
|
|
3
3
|
|
4
4
|
class TestStock < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
@row = {
|
7
|
+
'Symbol' => 'TESTING',
|
8
|
+
'Name' => 'Testing, Inc.',
|
9
|
+
'LastSale' => '1.23',
|
10
|
+
'MarketCap' => '123456789',
|
11
|
+
'Sector' => 'Consumer Services',
|
12
|
+
'Industry' => 'Other Specialty Stores'
|
13
|
+
}
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_create_a_stock
|
16
|
-
stock = TickerFetcher::Stock.new(
|
17
|
-
assert_equal(@
|
18
|
-
assert_equal(@
|
19
|
-
assert_equal(@
|
20
|
-
assert_equal(@
|
21
|
-
assert_equal(@
|
22
|
-
assert_equal(@
|
23
|
-
assert_equal(@industry, stock.industry)
|
17
|
+
stock = TickerFetcher::Stock.new(@row)
|
18
|
+
assert_equal(@row['Symbol'], stock.symbol)
|
19
|
+
assert_equal(@row['Name'], stock.name)
|
20
|
+
assert_equal(@row['LastSale'], stock.last_sale)
|
21
|
+
assert_equal(@row['MarketCap'], stock.market_cap)
|
22
|
+
assert_equal(@row['Sector'], stock.sector)
|
23
|
+
assert_equal(@row['Industry'], stock.industry)
|
24
24
|
end
|
25
25
|
end
|
data/ticker_fetcher.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ticker_fetcher"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.5.0"
|
7
7
|
s.authors = ["Matt White"]
|
8
8
|
s.email = ["mattw922@gmail.com"]
|
9
9
|
s.homepage = "http://github.com/whitethunder/ticker_fetcher"
|
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
13
13
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
14
14
|
s.require_paths = ["lib"]
|
15
|
+
s.license = "MIT"
|
15
16
|
|
16
|
-
s.add_development_dependency("fakeweb")
|
17
|
+
s.add_development_dependency("fakeweb", "~> 1.3.0", ">= 1.3.0")
|
17
18
|
end
|
18
19
|
|
metadata
CHANGED
@@ -1,32 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ticker_fetcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt White
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: fakeweb
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 1.3.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.0
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- - ">="
|
28
31
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
32
|
+
version: 1.3.0
|
30
33
|
description: Retrieves tickers, names, and other useful data for all stocks listed
|
31
34
|
on the 3 major US exchanges (NYSE, NASDAQ, AMEX).
|
32
35
|
email:
|
@@ -35,7 +38,7 @@ executables: []
|
|
35
38
|
extensions: []
|
36
39
|
extra_rdoc_files: []
|
37
40
|
files:
|
38
|
-
- .gitignore
|
41
|
+
- ".gitignore"
|
39
42
|
- Gemfile
|
40
43
|
- LICENSE
|
41
44
|
- README.rdoc
|
@@ -51,28 +54,28 @@ files:
|
|
51
54
|
- test/test_stock.rb
|
52
55
|
- ticker_fetcher.gemspec
|
53
56
|
homepage: http://github.com/whitethunder/ticker_fetcher
|
54
|
-
licenses:
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
55
60
|
post_install_message:
|
56
61
|
rdoc_options: []
|
57
62
|
require_paths:
|
58
63
|
- lib
|
59
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
65
|
requirements:
|
62
|
-
- -
|
66
|
+
- - ">="
|
63
67
|
- !ruby/object:Gem::Version
|
64
68
|
version: '0'
|
65
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
70
|
requirements:
|
68
|
-
- -
|
71
|
+
- - ">="
|
69
72
|
- !ruby/object:Gem::Version
|
70
73
|
version: '0'
|
71
74
|
requirements: []
|
72
75
|
rubyforge_project:
|
73
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.4.5
|
74
77
|
signing_key:
|
75
|
-
specification_version:
|
78
|
+
specification_version: 4
|
76
79
|
summary: Fetches all tickers and other useful data for NYSE, NASDAQ, and AMEX exchanges.
|
77
80
|
test_files:
|
78
81
|
- test/amex_test_data.csv
|