Class: QuickTicker::Cli
- Inherits:
-
Object
- Object
- QuickTicker::Cli
- Defined in:
- lib/cli.rb
Instance Attribute Summary collapse
-
#exit_message ⇒ Object
Returns the value of attribute exit_message.
-
#last_option_lambda ⇒ Object
Returns the value of attribute last_option_lambda.
-
#scraper ⇒ Object
Returns the value of attribute scraper.
-
#stock ⇒ Object
Returns the value of attribute stock.
Instance Method Summary collapse
- #call_stock_option_menu(option_hash) ⇒ Object
- #display_stock_description ⇒ Object
- #display_stock_header ⇒ Object
- #display_stock_option_menu(option_1_string, option_2_string) ⇒ Object
- #display_stock_quote ⇒ Object
- #display_stock_related_companies ⇒ Object
- #fetch_stock_description ⇒ Object
- #fetch_stock_quote ⇒ Object
- #fetch_stock_related_companies ⇒ Object
-
#initialize(cli = nil) ⇒ Cli
constructor
A new instance of Cli.
- #process_stock_option_menu_input(input, option_1_lambda, option_2_lambda, option_3_lambda) ⇒ Object
- #symbol_validation(symbol, fixture_url = nil) ⇒ Object
- #welcome(mode_name, mode_lambda) ⇒ Object
Constructor Details
#initialize(cli = nil) ⇒ Cli
Returns a new instance of Cli.
7 8 9 |
# File 'lib/cli.rb', line 7 def initialize(cli = nil) self.scraper = QuickTicker::Scraper.new(self) end |
Instance Attribute Details
#exit_message ⇒ Object
Returns the value of attribute exit_message.
5 6 7 |
# File 'lib/cli.rb', line 5 def @exit_message end |
#last_option_lambda ⇒ Object
Returns the value of attribute last_option_lambda.
5 6 7 |
# File 'lib/cli.rb', line 5 def last_option_lambda @last_option_lambda end |
#scraper ⇒ Object
Returns the value of attribute scraper.
5 6 7 |
# File 'lib/cli.rb', line 5 def scraper @scraper end |
#stock ⇒ Object
Returns the value of attribute stock.
5 6 7 |
# File 'lib/cli.rb', line 5 def stock @stock end |
Instance Method Details
#call_stock_option_menu(option_hash) ⇒ Object
64 65 66 |
# File 'lib/cli.rb', line 64 def (option_hash) ((option_hash[:option_1_string], option_hash[:option_2_string]), option_hash[:option_1_lambda], option_hash[:option_2_lambda], option_hash[:last_option_lambda]) end |
#display_stock_description ⇒ Object
30 31 32 33 |
# File 'lib/cli.rb', line 30 def display_stock_description print "#{self.stock.description.sector} : #{self.stock.description.industry}\n\n" puts "#{self.stock.description.summary}".fit end |
#display_stock_header ⇒ Object
16 17 18 |
# File 'lib/cli.rb', line 16 def display_stock_header print "\n#{self.stock.name} (#{self.stock.exchange}:#{self.stock.symbol})\n\n" end |
#display_stock_option_menu(option_1_string, option_2_string) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/cli.rb', line 68 def (option_1_string, option_2_string) gets puts "1. #{option_1_string} for #{self.stock.symbol}." puts "2. #{option_2_string} for #{self.stock.symbol}." puts "3. Enter another ticker symbol." puts "Enter any other key to exit." gets.strip.gsub('.', '') end |
#display_stock_quote ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/cli.rb', line 20 def display_stock_quote puts "Current: #{self.stock.quote.price} #{stock.quote.change}(#{stock.quote.change_pct}%)" puts "Open: #{self.stock.quote.open}" puts "Volume: #{self.stock.quote.volume}" puts "Avg Vol: #{self.stock.quote.volume_avg}" puts "Mkt Cap: #{self.stock.quote.mkt_cap}" puts "P/E(ttm): #{self.stock.quote.pe_ttm}" puts "Yield: #{self.stock.quote.div_yld}%" end |
#display_stock_related_companies ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cli.rb', line 35 def output = "Symbol Price Mkt Cap\n" self.stock..each do || output += (.symbol + ' ' * 8)[0,8] output += (.price + ' ' * 8)[0,8] output += ("#{.change}(#{.change_pct}%)" + ' ' * 16)[0,16] output += .mkt_cap + "\n" end puts output end |
#fetch_stock_description ⇒ Object
52 53 54 55 56 |
# File 'lib/cli.rb', line 52 def fetch_stock_description self.display_stock_header self.display_stock_description self.({ option_1_string: "Display a quote", option_2_string: "Display related companies", option_1_lambda: -> { self.fetch_stock_quote }, option_2_lambda: -> { self. }, last_option_lambda: -> {self.last_option_lambda.()} }) end |
#fetch_stock_quote ⇒ Object
46 47 48 49 50 |
# File 'lib/cli.rb', line 46 def fetch_stock_quote self.display_stock_header self.display_stock_quote self.({ option_1_string: "Display a company description", option_2_string: "Display related companies", option_1_lambda: -> { self.fetch_stock_description }, option_2_lambda: -> { self. }, last_option_lambda: -> {self.last_option_lambda.()} }) end |
#fetch_stock_related_companies ⇒ Object
58 59 60 61 62 |
# File 'lib/cli.rb', line 58 def self.display_stock_header self. self.({ option_1_string: "Display a quote", option_2_string: "Display a company description", option_1_lambda: -> { self.fetch_stock_quote }, option_2_lambda: -> { self.fetch_stock_description }, last_option_lambda: -> {self.last_option_lambda.()} }) end |
#process_stock_option_menu_input(input, option_1_lambda, option_2_lambda, option_3_lambda) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cli.rb', line 77 def (input, option_1_lambda, option_2_lambda, option_3_lambda) if input == "1" option_1_lambda.() elsif input == "2" option_2_lambda.() elsif input == "3" option_3_lambda.() else puts self. return nil end end |
#symbol_validation(symbol, fixture_url = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cli.rb', line 90 def symbol_validation(symbol, fixture_url = nil) # stock_array[0] is a stock if one was succesfully created and nil otherwise. # stock_array[1] indicates whether the symbol cooresponds to a mutual fund. stock_array = self.scraper.load_gfs(symbol, fixture_url) self.stock = stock_array[0] valid = self.stock.nil? ? false : true puts "Invalid ticker symbol." if !valid puts "Mutual funds are not currently not supported." if stock_array[1] self.fetch_stock_quote if valid # returns an array. # array[0] - whether the entered symbol was valid # array[1] = stock_array[1] - whether the entered # symbol was a mutal fund. [valid, stock_array[1]] end |
#welcome(mode_name, mode_lambda) ⇒ Object
11 12 13 14 |
# File 'lib/cli.rb', line 11 def welcome(mode_name, mode_lambda) print "\nWelcome to " + mode_name + "!\n" mode_lambda.() end |