stock_info 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 476a3a1026da6b7478795475012c06dd0b30c9f0
4
- data.tar.gz: f7d79d9b713ae7b4b0ac0485e988ba0da206b2b3
3
+ metadata.gz: 011e27a1f7a2a47b605c8c724c01daa80aed357d
4
+ data.tar.gz: 02ac7c7e2973528f4c7ca87d994ee0b6cde5efd7
5
5
  SHA512:
6
- metadata.gz: e659a227c1c0dbf1569ebf2173d128e97378afe83446161f74b9d9915122b8171b20f2225174fd8add8467414a86f95e5c1310310d30962d6953174ab3db705c
7
- data.tar.gz: 4061642252a6bd222ada67d27b7f0716a9366a82b6911469ec257fe7b008f801307d19f1390ee382103f9380d77eeb389d9b70b51329fb7337b3f13e31508bc2
6
+ metadata.gz: 6eaccafdd840dee4a66e390777ff08c8d6720e4cdcbe118ee9575c170c91e019104425a44b9b8feaf475839020ea5a0ddddb70c4cfc2fee63fe4e31648fe8eb7
7
+ data.tar.gz: cf818c0d918575b96cb020cf6b72ff92db81b60ce8989ddeeb757bc30f539ed6637fb5117c7f2aa133006638fc5235059d0e1a76de68f04cd58abff6d69ce047
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stock_info (0.1.2)
4
+ stock_info (0.1.3)
5
5
  nokogiri (~> 1.10)
6
6
 
7
7
  GEM
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'bundler/setup'
3
2
  require_relative '../lib/stock_info'
4
3
  StockInfo::CLI.new.call
@@ -15,12 +15,12 @@ class StockInfo::CLI
15
15
  input = nil
16
16
  while input != 'exit'
17
17
  puts 'Enter the ticker symbol of a stock you would like more info on.'
18
- puts "Other commands: 'exit' - exits stock-info, 'trending' - shows trending stocks."
18
+ puts "Other commands: 'exit' - exits stock-info, 'trending' - refresh trending stocks."
19
19
  input = gets.strip.downcase
20
20
  if input == 'trending'
21
21
  trending_tickers
22
22
  elsif StockInfo::Stock.check_symbol(input.upcase) == true
23
- stock = StockInfo::Stock.new(input.upcase)
23
+ stock = StockInfo::Stock.create_or_return(input.upcase)
24
24
  stock.print_info
25
25
  puts 'View recent news articles related to this stock? (yes/no)'
26
26
  news_bool = gets.strip[0].downcase
@@ -1,10 +1,31 @@
1
1
  class StockInfo::Stock
2
2
  attr_accessor :company, :symbol, :daily_change, :price, :news, :earnings, :rvol, :optionable, :short_ratio
3
3
  @@trending = []
4
+ @@all = []
4
5
  def initialize(symbol)
5
6
  @symbol = symbol
6
7
  @news = []
7
8
  get_info(symbol)
9
+ @@all << self
10
+ end
11
+
12
+ def self.create_or_return(symbol)
13
+ if self.market_open || @@all.any? {|stock| stock.symbol == symbol}
14
+ if self.market_open
15
+ stock = @@all.select {|stock| stock.symbol == symbol }[0]
16
+ stock.get_info(symbol)
17
+ stock
18
+ else
19
+ stock = @@all.select {|stock| stock.symbol == symbol}[0]
20
+ end
21
+ else
22
+ self.new(symbol)
23
+ end
24
+ end
25
+
26
+ def self.market_open
27
+ time = Time.now.localtime('-05:00')
28
+ (time.saturday? || time.sunday? || time.hour > 20 || time.hour < 4) ? false : true
8
29
  end
9
30
 
10
31
  def self.check_symbol(symbol)
@@ -38,20 +59,19 @@ class StockInfo::Stock
38
59
  end
39
60
 
40
61
  def self.print_trending
41
- trending.each do |stock|
62
+ self.trending.each do |stock|
42
63
  puts "#{stock.symbol} - Price: #{stock.price} - Change: #{stock.daily_change} - Relative Volume: #{stock.rvol}"
43
64
  end
44
65
  end
45
66
 
46
67
  def self.trending
47
- time = Time.now.localtime('-05:00')
48
- unless (time.saturday? || time.sunday? || time.hour > 20 || time.hour < 4) && @@trending.any?
68
+ if self.market_open || @@trending.empty?
49
69
  i = 0
50
70
  doc = Nokogiri::HTML(open('https://finviz.com/screener.ashx?v=110&s=ta_mostactive'))
51
71
  10.times do
52
72
  symbol = doc.css('tr.table-dark-row-cp a.screener-link-primary')[i].text
53
73
  i += 1
54
- @@trending << new(symbol)
74
+ @@trending << self.create_or_return(symbol)
55
75
  end
56
76
  end
57
77
  @@trending
@@ -1,3 +1,3 @@
1
1
  module StockInfo
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stock_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kunkel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-09 00:00:00.000000000 Z
11
+ date: 2019-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler