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.
@@ -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
File without changes
data/Rakefile CHANGED
File without changes
@@ -2,4 +2,9 @@ require 'ticker_fetcher/retriever'
2
2
  require 'ticker_fetcher/stock'
3
3
 
4
4
  module TickerFetcher
5
- end
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
- Symbol = 0
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
- @exchange_urls.each { |exchange, url| @exchanges[exchange] = parse_exchange(exchange, url) }
16
+ EXCHANGE_URLS.each { |exchange, url| @exchanges[exchange] = parse_exchange(exchange, url) }
30
17
  else
31
- @exchanges[exchange] = parse_exchange(exchange, @exchange_urls[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, :headers => true).inject([]) do |stocks, row|
48
- stocks << TickerFetcher::Stock.new([ticker(row), name(row), last_sale(row), market_cap(row), ipo_year(row), sector(row), industry(row)])
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
@@ -1,15 +1,14 @@
1
1
  module TickerFetcher
2
2
  class Stock
3
- attr_reader :symbol, :name, :last_sale, :market_cap, :ipo_year, :sector, :industry
3
+ attr_reader :symbol, :name, :last_sale, :market_cap, :sector, :industry
4
4
 
5
5
  def initialize(data)
6
- @symbol = data[TickerFetcher::Retriever::Symbol]
7
- @name = data[TickerFetcher::Retriever::Name]
8
- @last_sale = data[TickerFetcher::Retriever::LastSale]
9
- @market_cap = data[TickerFetcher::Retriever::MarketCap]
10
- @ipo_year = data[TickerFetcher::Retriever::IPOYear]
11
- @sector = data[TickerFetcher::Retriever::Sector]
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
File without changes
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'fakeweb'
4
+ require 'ticker_fetcher'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
File without changes
File without changes
@@ -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
- @retriever.exchange_urls.each do |exchange, url|
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)
@@ -3,23 +3,23 @@ require 'ticker_fetcher/stock'
3
3
 
4
4
  class TestStock < Test::Unit::TestCase
5
5
  def setup
6
- @symbol = 'TESTING'
7
- @name = 'Testing, Inc.'
8
- @last_sale = '1.23'
9
- @market_cap = '123456789'
10
- @ipo_year = '2000'
11
- @sector = 'Consumer Services'
12
- @industry = 'Other Specialty Stores'
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([@symbol, @name, @last_sale, @market_cap, @ipo_year, @sector, @industry])
17
- assert_equal(@symbol, stock.symbol)
18
- assert_equal(@name, stock.name)
19
- assert_equal(@last_sale, stock.last_sale)
20
- assert_equal(@market_cap, stock.market_cap)
21
- assert_equal(@ipo_year, stock.ipo_year)
22
- assert_equal(@sector, stock.sector)
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ticker_fetcher"
6
- s.version = "0.4.2"
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.4.2
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: 2013-01-17 00:00:00.000000000 Z
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: '0'
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: '0'
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: 1.8.23
76
+ rubygems_version: 2.4.5
74
77
  signing_key:
75
- specification_version: 3
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