sp500 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bde8bb210baa0c607d895e1aba3ac4dae1206ce903b30d429005105fa0f47ce9
4
- data.tar.gz: 7a3650a9532c640444ae81cb3e6a6425bff24e564fdb2b0615f407ab6ab2dbc4
3
+ metadata.gz: 2a604d93c7141470e2ac20b578b80220babdc1738a0dd26f6d5c9144683d9a28
4
+ data.tar.gz: b62df39d1ba51ee0722e440986e10c2b69284a44de5c32a650f9ac4e6e0ac0a4
5
5
  SHA512:
6
- metadata.gz: f2dd36ed20e9b715a8af2646fe313fe41094cd862e794b387e4aa1e4f792892cebe9f0fe98c60ef18b31eb8ccf7230dc27eff9bfadc0680ad4fb9dc69debcc4b
7
- data.tar.gz: fc5e588785cfa7c2059c5fd47806c5aa2c1ae6c8e4da18f85b407cf8a1f4b271bfc038c34853346165a9a84c7a10726248a3db21cc107b0b2dd9908cdccc51f5
6
+ metadata.gz: cadd84645d95ef8ac0bc5980da19e998d0020bcc1af25eb01a3a55fd7bd649ccb464a72622cd41213749508e60ab02ac093bafe69b3f194b2c67bf61cb61e4c8
7
+ data.tar.gz: 04dd5fcd88e26df60acea75572af624c71199b8f06582058fae950c8626af537228e51b5d591d6f705927757dfb1c571a5c7ac4bfff8ef2cad5727290aa7670b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sp500 (0.1.1)
4
+ sp500 (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- TODO: Write usage instructions here
31
+ Please see above in *Features* section
32
32
 
33
33
  ## Development
34
34
 
data/lib/sp500.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'open-uri'
2
2
  require 'nokogiri'
3
- require 'pp'
4
- require 'byebug'
5
3
  require 'date'
6
4
 
7
- require "sp500/version"
8
5
  require "tools/string_extensions"
6
+ require "tools/hash_constructed"
7
+
8
+ require "sp500/version"
9
+ require "sp500/stock"
9
10
 
10
11
  module Sp500
11
12
  using Tools::StringExtension
@@ -28,7 +29,7 @@ module Sp500
28
29
 
29
30
  next if cells.empty?
30
31
 
31
- {
32
+ Stock.new(
32
33
  ticker_symbol: cells[0][0],
33
34
  nyse_quote_url: cells[0][1],
34
35
  firm_name: cells[1][0],
@@ -41,22 +42,22 @@ module Sp500
41
42
  firm_hq_address_url: cells[5][1],
42
43
  sp500_introduction_date: (cells[6].blank? ? 'n/a' : Date.parse(cells[6])),
43
44
  central_index_key: cells[7]
44
- }
45
+ )
45
46
  end.compact
46
47
  end
47
48
 
48
49
  def sectors
49
- list.map do |item|
50
- item[:gics_sector]
50
+ list.map do |stock|
51
+ stock.gics_sector
51
52
  end.uniq.sort
52
53
  end
53
54
 
54
55
  def industries
55
56
  result = {}
56
57
 
57
- list.each do |item|
58
- result[item[:gics_sector]] ||= []
59
- result[item[:gics_sector]] << item[:gics_sub_industry] unless result[item[:gics_sector]].include?(item[:gics_sub_industry])
58
+ list.each do |stock|
59
+ result[stock.gics_sector] ||= []
60
+ result[stock.gics_sector] << stock.gics_sub_industry unless result[stock.gics_sector].include?(stock.gics_sub_industry)
60
61
  end
61
62
 
62
63
  result
@@ -65,9 +66,9 @@ module Sp500
65
66
  def by_sectors
66
67
  result = {}
67
68
 
68
- list.each do |item|
69
- result[item[:gics_sector]] ||= []
70
- result[item[:gics_sector]] << item
69
+ list.each do |stock|
70
+ result[stock.gics_sector] ||= []
71
+ result[stock.gics_sector] << stock
71
72
  end
72
73
 
73
74
  result
@@ -76,10 +77,10 @@ module Sp500
76
77
  def by_industries
77
78
  result = {}
78
79
 
79
- list.each do |item|
80
- result[item[:gics_sector]] ||= {}
81
- result[item[:gics_sector]][item[:gics_sub_industry]] ||= []
82
- result[item[:gics_sector]][item[:gics_sub_industry]] << item
80
+ list.each do |stock|
81
+ result[stock.gics_sector] ||= {}
82
+ result[stock.gics_sector][stock.gics_sub_industry] ||= []
83
+ result[stock.gics_sector][stock.gics_sub_industry] << stock
83
84
  end
84
85
 
85
86
  result
@@ -0,0 +1,7 @@
1
+ module Sp500
2
+ class Stock
3
+ include Tools::HashConstructed
4
+
5
+ attr_accessor :ticker_symbol, :nyse_quote_url, :firm_name, :firm_wikipedia_url, :sec_filling_type, :sec_fillings_doc_url, :gics_sector, :gics_sub_industry, :firm_hq_address, :firm_hq_address_url, :sp500_introduction_date, :central_index_key
6
+ end
7
+ end
data/lib/sp500/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sp500
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Tools
2
+ module HashConstructed
3
+ def initialize(h)
4
+ h.each {|attr_name,attr_value| public_send("#{attr_name}=", attr_value)}
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sp500
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Kifer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-11 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,9 @@ files:
99
99
  - bin/console
100
100
  - bin/setup
101
101
  - lib/sp500.rb
102
+ - lib/sp500/stock.rb
102
103
  - lib/sp500/version.rb
104
+ - lib/tools/hash_constructed.rb
103
105
  - lib/tools/string_extensions.rb
104
106
  - sp500.gemspec
105
107
  homepage: https://github.com/FranckyU/sp500