Sha256: 8c162ed70b604c9008c580642af0c00c5d26c9fabf7eaa70f0214b70bc31353a

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

module StockGains 
  class StockGains::CLI

    def call
      StockGains::Portfolio.new.call
      start
    end

    def start
      input = ""
      begin
        puts "\nTo view more stock information, enter the number associated with"
        puts "the stock or enter 'all' to view all of the stocks in your portfolio."
        puts "Separate digits with a space to view multiple stocks."
        puts "(Enter 'e' at anytime throughout the program to exit)\n\n"
        input = gets.strip.scan(/\w+/)
      end until valid_input?(input) || input.first == "e"
      
      if input.first != "e"   
        input.first == "all" ? find_all : find(input)
        stock_lookup
      end
      puts "\nGoodbye!"
    end

    def valid_input?(input)
      input.first == "all" || input.map(&:to_i).all?{ |n| n.between?(1, StockGains::Stock.all.count)}
    end

    def find_all
      print_stock_info(StockGains::Stock.all)
    end

    def find(stock)
      print_stock_info(stock.map(&:to_i).collect{ |s| StockGains::Stock.all[s-1] })
    end

    def print_stock_info(stocks)
      puts "\n"
      stocks.each do |s|
        puts "#{s.name}".center(67)
        puts " " + "-" * 68
        puts " Asking Price:     $#{s.cur_price}".ljust(37, " ") + "Day's Range:    $#{s.d_range}"
        puts " Previous Close:   $#{s.prev_close}".ljust(37, " ") + "52 Week Range:  $#{s.y_range}"
        puts " Open:             $#{s.open}".ljust(37, " ") + "1 Year Target:  $#{s.year_trgt}"
        puts " P/E Ratio:        $#{s.pe}".ljust(37, " ") + "EPS:            $#{s.eps}"
        puts " Day's +/-:        $#{s.days_value}".ljust(37, " ") + "Shares:        #{s.shares}"
        puts "\n\n"
      end
    end

    def stock_lookup
      StockGains::StockLookup.new.call
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stock-gains-0.1.6 lib/stock-gains/cli.rb
stock-gains-0.1.5 lib/stock-gains/cli.rb
stock-gains-0.1.3 lib/stock-gains/cli.rb