qticker 1.0.5
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 +7 -0
- data/bin/qticker +7 -0
- data/config/environment.rb +15 -0
- data/lib/cli.rb +51 -0
- data/lib/desc.rb +8 -0
- data/lib/dev_cli.rb +58 -0
- data/lib/fixtures/FBIOX.html +1120 -0
- data/lib/fixtures/IBM.html +1269 -0
- data/lib/fixtures/MSFT.html +1268 -0
- data/lib/fixtures/QQQ.html +1059 -0
- data/lib/main_cli.rb +39 -0
- data/lib/qticker.rb +1 -0
- data/lib/quote.rb +13 -0
- data/lib/scraper.rb +82 -0
- data/lib/stock.rb +17 -0
- data/lib/stock_attr.rb +10 -0
- data/lib/table.rb +22 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 494c931926f1f8c3f6192e66db4a075a35a56198
|
4
|
+
data.tar.gz: b2f124d4e050d554f5681108b28e0f62ce82424f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67182ffe4f96c7427ac6822a603e2884786859dcd8c27074d35d2a2b0acbe13a78647cce4d052a48f1ad8458a795aae55dc06ab864ce336601b01831c783ba93
|
7
|
+
data.tar.gz: 2e0286a1c602d99806552cad09ead288e5d4387fc9f0c1722b4d94de2f2f677e514fea9532d4a3cf84425344f0679b553603071f9b0edffafc9cbfd2e9d930aa
|
data/bin/qticker
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'require_all'
|
3
|
+
require 'word_wrap'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'word_wrap/core_ext'
|
6
|
+
|
7
|
+
require_relative '../lib/cli.rb'
|
8
|
+
require_relative '../lib/table.rb'
|
9
|
+
require_relative '../lib/stock_attr.rb'
|
10
|
+
require_relative '../lib/desc.rb'
|
11
|
+
require_relative '../lib/dev_cli.rb'
|
12
|
+
require_relative '../lib/main_cli.rb'
|
13
|
+
require_relative '../lib/quote.rb'
|
14
|
+
require_relative '../lib/scraper.rb'
|
15
|
+
require_relative '../lib/stock.rb'
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Cli
|
2
|
+
|
3
|
+
attr_accessor :stock, :scraper
|
4
|
+
|
5
|
+
def initialize(cli = nil)
|
6
|
+
self.scraper = Scraper.new(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def welcome(mode_name, mode_lambda)
|
10
|
+
print "\nWelcome to " + mode_name + "!\n"
|
11
|
+
mode_lambda.()
|
12
|
+
end
|
13
|
+
|
14
|
+
def display_quote
|
15
|
+
self.stock.display
|
16
|
+
self.stock.quote.display
|
17
|
+
self.stock_option_menu("Display a company description", -> { self.display_desc })
|
18
|
+
end
|
19
|
+
|
20
|
+
def display_desc
|
21
|
+
self.stock.display
|
22
|
+
self.stock.desc.display
|
23
|
+
self.stock_option_menu("Redisplay your quote", -> { self.display_quote })
|
24
|
+
end
|
25
|
+
|
26
|
+
def stock_option_menu(opt_1_string, opt_1_lambda = nil)
|
27
|
+
gets
|
28
|
+
puts "1. #{opt_1_string} for #{self.stock.symbol}."
|
29
|
+
puts "2. Enter another ticker symbol."
|
30
|
+
puts "Enter any other key to exit."
|
31
|
+
gets.strip.gsub('.', '')
|
32
|
+
end
|
33
|
+
|
34
|
+
def symbol_validation(symbol, valid, fixture_url = nil)
|
35
|
+
# stock_array[0] is a stock if one was succesfully created and nil otherwise.
|
36
|
+
# stock_array[1] indicates whether the symbol cooresponds to a mutual fund.
|
37
|
+
stock_array = self.scraper.load_gfs(symbol, fixture_url)
|
38
|
+
self.stock = stock_array[0]
|
39
|
+
valid = self.stock.nil? ? false : true
|
40
|
+
puts "Invalid ticker symbol." if !valid
|
41
|
+
puts "Mutual funds are not currently not supported." if stock_array[1]
|
42
|
+
self.display_quote if valid
|
43
|
+
# returns an array.
|
44
|
+
# array[0] - whether the entered symbol was valid
|
45
|
+
# array[1] = stock_array[1] - whether the entered
|
46
|
+
# symbol was a mutal fund.
|
47
|
+
[valid, stock_array[1]]
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
data/lib/desc.rb
ADDED
data/lib/dev_cli.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class DevCli < Cli
|
2
|
+
|
3
|
+
attr_accessor :main
|
4
|
+
|
5
|
+
def initialize(main_cli)
|
6
|
+
super(main_cli)
|
7
|
+
self.main = main_cli
|
8
|
+
end
|
9
|
+
|
10
|
+
def option_menu
|
11
|
+
puts "\nPlease select a fixture to load:"
|
12
|
+
puts "1. Load MSFT.html"
|
13
|
+
puts "2. Load IBM.html"
|
14
|
+
puts "3. Load QQQ.html"
|
15
|
+
puts "4. Load FBIOX.html"
|
16
|
+
puts "Or enter any other key to return to"
|
17
|
+
puts "your regularly scheduled program."
|
18
|
+
input = gets.strip.gsub('.', '')
|
19
|
+
path = File.expand_path(File.dirname(__FILE__)).chomp('bin') + '/fixtures/'
|
20
|
+
if input == "1"
|
21
|
+
valid = self.symbol_validation("MSFT", false, path + "MSFT.html")
|
22
|
+
elsif input == "2"
|
23
|
+
valid = self.symbol_validation("IBM", false, path + "IBM.html")
|
24
|
+
elsif input == "3"
|
25
|
+
valid = self.symbol_validation("QQQ", false, path + "QQQ.html")
|
26
|
+
elsif input == "4"
|
27
|
+
valid = self.symbol_validation("FBIOX", false, path + "FBIOX.html")
|
28
|
+
else
|
29
|
+
puts "Leaving Developer Mode and resuming program."
|
30
|
+
end
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def stock_option_menu(opt_1_string, opt_1_lambda)
|
35
|
+
input = super(opt_1_string, opt_1_lambda)
|
36
|
+
if input == "1"
|
37
|
+
opt_1_lambda.()
|
38
|
+
elsif input == "2"
|
39
|
+
self.option_menu
|
40
|
+
else
|
41
|
+
puts "Leaving Developer Mode and resuming program."
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def symbol_validation(symbol, valid, fixture_url = nil)
|
47
|
+
valid_array = super(symbol, valid, fixture_url)
|
48
|
+
if valid_array[1] # whether entered symbol was a mutual fund
|
49
|
+
puts ""
|
50
|
+
option_menu
|
51
|
+
end
|
52
|
+
valid_array[0] # returns whether entered symbol was valid
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
end
|