top_stock_movers 0.1.6 → 0.1.7

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
  SHA256:
3
- metadata.gz: d005bd3240f3c613d81cad2caa79e3d8ebad30a49293b215bb04b7e8e0bb4343
4
- data.tar.gz: f9732d8bdd930b4da710f0f59e320c01f06adae1267144d3738b287ac87b41ad
3
+ metadata.gz: fb457b4882724e5abc9f53646d59c575728d91fbbeb8a1d6528e150e0fbd6ab7
4
+ data.tar.gz: 4e47459e3c54be0bbbf303834a21bff75a8e4e2df53847d1ff8b5c3fb157ec08
5
5
  SHA512:
6
- metadata.gz: 579214486389fb48ea7835d2da2a258b2eb1225420d70d4bff9781f6513a030955d9118d340e85c4f3a72ea7ad83246a2fb51973e00875b7dc0981f641342f96
7
- data.tar.gz: 3ddad1affff2a151887d47b38b15adfecc5bec1026f936aa724118117d81db4e231428791d18e66530e7863904241d18cd2d4f43bec4afd29c59c860717e9222
6
+ metadata.gz: c3c04d80cf69d4d9d9c2f0ee9485ca37d849dc5c4d89f3d1c0b2e2b01c58db591ef43726e41d13925517e766ee5e1762b288db0a674de9a02048e9680b59921b
7
+ data.tar.gz: b9b1efd93d5dae3da7178324567a105e5ce19e8b7a9f17367752f538c1842f81df8e6561febb63ef28d3bf3d0eb7590197eb6553093d156bc2ce6cde98fc65c3
@@ -8,3 +8,5 @@ require 'net/http'
8
8
  require_relative "./top_stock_movers/version"
9
9
  require_relative './top_stock_movers/cli'
10
10
  require_relative './top_stock_movers/stocks'
11
+ require_relative './top_stock_movers/scraper'
12
+ require_relative './top_stock_movers/viewing_options.rb'
@@ -4,30 +4,6 @@ class TopStockMovers::CLI
4
4
  list_viewing_options
5
5
  list_stocks
6
6
  menu
7
- goodbye
8
- end
9
-
10
- # This Viewing_options class is what is used to allow the program to view the 7 different sorting options
11
- # from the website and is the information used to populate the first list selection. It also is what is used
12
- # to provide the most relevant information and sorting options for the list_stocks method.
13
- class Viewing_options
14
- attr_accessor :name, :desc, :sorter
15
-
16
- @@all = []
17
-
18
- def self.all
19
- @@all
20
- end
21
-
22
- viewing_options = [["Gainers", "Stocks that have increased the most in price", "percent_change-pos"], ["Losers", "Stocks that have lost most of their value", "percent_change-neg"], ["Active" , "Stocks that have been traded the most", "volume"], ["Most-Volatile", "The fluctuation of price in any given timeframe", "percent_change-abs"], ["Overbought", "Stocks that significantly increased in price due a large demand", "rating"], ["Oversold", "Stock prices have decreased substantially", "rating"], ["Large-Cap", "Largest companies by market cap", "market_cap"]]
23
-
24
- viewing_options.each do |array|
25
- option = self.new
26
- option.name = array[0]
27
- option.desc = array[1]
28
- option.sorter = array[2]
29
- @@all << option
30
- end
31
7
  end
32
8
 
33
9
  @selection = nil
@@ -36,11 +12,11 @@ class TopStockMovers::CLI
36
12
  puts ""
37
13
  puts "How would you like to view today's Stock Market?? please enter corresponding number"
38
14
  puts ""
39
- Viewing_options.all.each.with_index(1) do |option, i|
15
+ TopStockMovers::Viewing_options.all.each.with_index(1) do |option, i|
40
16
  puts "#{i}. #{option.name} -- #{option.desc}"
41
17
  end
42
18
  input = gets.strip.to_i - 1
43
- @selection = Viewing_options.all[input]
19
+ @selection = TopStockMovers::Viewing_options.all[input]
44
20
  end
45
21
 
46
22
  def list_stocks
@@ -49,8 +25,8 @@ class TopStockMovers::CLI
49
25
  puts "------------------------------"
50
26
 
51
27
  #The line below allows me to scrape 7 different url's by changing the url according to the users selection
52
- TopStockMovers::Stocks.scrape_tradingview(@selection.name.downcase) if TopStockMovers::Stocks.all == []
53
- @stocks = TopStockMovers::Stocks.all
28
+ TopStockMovers::Scraper.scrape_tradingview(@selection.name.downcase) if TopStockMovers::Stocks.find_by_category(@selection.name.downcase).length == 0
29
+ @stocks = TopStockMovers::Stocks.find_by_category(@selection.name.downcase)
54
30
  #This case statement is using the Viewing_options instance originally selected by the user to output
55
31
  #the most relevant data per the selection and sorts accordingly. For example "% change" for Gainers, or "volume" for Active
56
32
  case @selection.sorter
@@ -123,6 +99,7 @@ class TopStockMovers::CLI
123
99
  list_stocks
124
100
  menu
125
101
  elsif input == 'exit'
102
+ goodbye
126
103
  else
127
104
  menu
128
105
  end
@@ -1,32 +1,17 @@
1
1
  class TopStockMovers::Stocks
2
- attr_accessor :ticker_symbol, :name, :price, :percent_change, :change, :rating, :sector, :url, :volume, :market_cap
2
+ attr_accessor :category, :ticker_symbol, :name, :price, :percent_change, :change, :rating, :sector, :url, :volume, :market_cap
3
3
 
4
4
  @@all = []
5
5
 
6
+ def initialize
7
+ @@all << self
8
+ end
9
+
6
10
  def self.all
7
11
  @@all
8
12
  end
9
13
 
10
- def self.scrape_tradingview(category)
11
- doc = Nokogiri::HTML(open("https://www.tradingview.com/markets/stocks-usa/market-movers-#{category}/"))
12
-
13
- doc.css('body div div#js-category-content div div div div#js-screener-container div table tbody tr').each do |row|
14
-
15
- stock = self.new
16
- stock.url = "https://www.tradingview.com#{row.css('a').attr('href').value}"
17
-
18
- stock_info = row.css('td').collect{|td| td.text}
19
-
20
- stock.ticker_symbol = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[0]
21
- stock.name = stock_info[0].split("\n\t\t\t\t\t\t").reject{|c| c.empty?}[1].gsub(/INC|LTD|PLC|3X|LLC|BOND|SPONSORED|\s{2,}|[,(-]/, "++").split("++")[0]
22
- stock.price = stock_info[1].to_f
23
- stock.percent_change = stock_info[2].to_f
24
- stock.change = stock_info[3].to_f
25
- stock.rating = stock_info[4]
26
- stock.volume = stock_info[5].to_f
27
- stock.market_cap = stock_info[6].to_f.round(1)
28
- stock.sector = stock_info[10]
29
- @@all << stock
30
- end
14
+ def self.find_by_category(category)
15
+ @@all.select {|stock| stock.category == category}
31
16
  end
32
17
  end
@@ -1,3 +1,3 @@
1
1
  module TopStockMovers
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top_stock_movers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Thomas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-17 00:00:00.000000000 Z
11
+ date: 2018-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler