Class: TopStockMovers::CLI
- Inherits:
-
Object
- Object
- TopStockMovers::CLI
- Defined in:
- lib/top_stock_movers/cli.rb
Defined Under Namespace
Classes: Viewing_options
Instance Method Summary collapse
- #call ⇒ Object
- #goodbye ⇒ Object
- #list_stocks ⇒ Object
- #list_viewing_options ⇒ Object
- #menu ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 |
# File 'lib/top_stock_movers/cli.rb', line 3 def call list_stocks goodbye end |
#goodbye ⇒ Object
131 132 133 134 |
# File 'lib/top_stock_movers/cli.rb', line 131 def goodbye puts "" puts "Thanks for using top-stock-movers!! Have a good day!" end |
#list_stocks ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/top_stock_movers/cli.rb', line 46 def list_stocks puts "" puts "Today's Top 25 #{@selection.name} stocks" puts "------------------------------" #The line below allows me to scrape 7 different url's by changing the url according to the users selection TopStockMovers::Stocks.scrape_tradingview(@selection.name.downcase) if TopStockMovers::Stocks.all == [] @stocks = TopStockMovers::Stocks.all #This case statement is using the Viewing_options instance originally selected by the user to output #the most relevant data per the selection and sorts accordingly. For example "% change" for Gainers, or "volume" for Active case @selection.sorter when "percent_change-pos" @stocks.sort{|a,b| b.percent_change <=> a.percent_change}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.percent_change}% - #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end when "percent_change-neg" @stocks.sort{|a,b| a.percent_change <=> b.percent_change}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.percent_change}% - #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end when "percent_change-abs" @stocks.sort{|a,b| b.percent_change.abs <=> a.percent_change.abs}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.percent_change}% - #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end when "volume" @stocks.sort{|a,b| b.volume <=> a.volume}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.volume}M -Vol #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end when "rating" @stocks.sort{|a,b| b. <=> a.}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.} -Rating - #{stock.percent_change}- #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end when "market_cap" @stocks.sort{|a,b| b.market_cap <=> a.market_cap}.each.with_index(1) do |stock, i| puts "#{i}. #{stock.market_cap}M -MktCap- #{stock.ticker_symbol} - #{stock.name}" break if i == 25 end end end |
#list_viewing_options ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/top_stock_movers/cli.rb', line 35 def puts "" puts "How would you like to view today's Stock Market?? please enter corresponding number" puts "" Viewing_options.all.each.with_index(1) do |option, i| puts "#{i}. #{option.name} -- #{option.desc}" end input = gets.strip.to_i - 1 @selection = Viewing_options.all[input] end |
#menu ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/top_stock_movers/cli.rb', line 90 def puts "Enter number of Stock you would like more info on, type 'view options' to view the initial sorting options, 'list' to list stocks, or exit to quit" input = gets.strip.downcase if input.to_i > 0 num = input.to_i - 1 puts"" puts "#{@stocks[num].name} --- #{@stocks[num].ticker_symbol}" puts "-----------------------------------------------------------------" puts "Sector = #{@stocks[num].sector}" puts "Rating = #{@stocks[num].}" puts "Price = $#{@stocks[num].price}" puts "Prc chg = #{@stocks[num].change}" puts "% chg = #{@stocks[num].percent_change}" puts "Volume = #{@stocks[num].volume}M" puts "Mkt Cap = #{@stocks[num].market_cap}M" puts "*** Would you like to open this stock's page for more info?(y/n) ***" input_2 = gets.strip.downcase if input_2 == "y" link = "#{@stocks[num].url}" if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ system "start #{link}" elsif RbConfig::CONFIG['host_os'] =~ /darwin/ system "open #{link}" elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ system "xdg-open #{link}" end else end elsif input == 'view options' call elsif input == 'list' list_stocks elsif input == 'exit' else end end |