stock_quote_cli 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -0
- data/.rspec +1 -1
- data/Gemfile +2 -4
- data/Gemfile.lock +11 -34
- data/LICENSE.txt +20 -0
- data/README.md +18 -40
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/lib/stock_quote_cli/cli.rb +160 -119
- data/lib/stock_quote_cli/history.rb +13 -0
- data/lib/stock_quote_cli/quote.rb +26 -0
- data/lib/stock_quote_cli.rb +12 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/stock_quote_cli_spec.rb +1 -19
- metadata +48 -48
- data/demo.gif +0 -0
- data/lib/stock_quote_cli/api.rb +0 -23
- data/lib/stock_quote_cli/text.rb +0 -23
- data/lib/stock_quote_cli/version.rb +0 -3
- data/stock_quote_cli.gemspec +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad69920aadb2c2fa8fb56d6445b5993028a65d87
|
4
|
+
data.tar.gz: 8004d95148338b143f44f61c831da97463581034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a153c670661adababc28f8df5a9d4a2adb03ba268130b2804e259e4c052754018660efa7a70da2e7d5bbdcb52609c8bb1d28696e613ab962719f1b9456d57726
|
7
|
+
data.tar.gz: 5581dbb17d453b050c22120d0e8ab50b8c09d60824ccd3e0e9947c9a32297dbd3b35c37e49f1ea394f4edba12ff529b4c69be9c4aefe97cffc0f84bbaa1185b2
|
data/.document
ADDED
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--color
|
1
|
+
--color
|
data/Gemfile
CHANGED
@@ -2,16 +2,14 @@ source "http://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
|
-
gem "thor"
|
6
|
-
gem "stock_quote"
|
5
|
+
gem "thor"
|
6
|
+
gem "stock_quote"
|
7
7
|
|
8
8
|
# Add dependencies to develop your gem here.
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
10
10
|
group :development do
|
11
11
|
gem "rspec", "~> 2.8.0"
|
12
|
-
gem "shoulda-matchers", "~> 2.7"
|
13
12
|
gem "rdoc", "~> 3.12"
|
14
13
|
gem "bundler", "~> 1.0"
|
15
14
|
gem "jeweler", "~> 1.8.7"
|
16
|
-
gem "pry", "~> 0.10"
|
17
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (4.2.0)
|
5
|
-
i18n (~> 0.7)
|
6
|
-
json (~> 1.7, >= 1.7.7)
|
7
|
-
minitest (~> 5.1)
|
8
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
-
tzinfo (~> 1.1)
|
10
4
|
addressable (2.3.5)
|
11
5
|
builder (3.2.2)
|
12
|
-
coderay (1.1.0)
|
13
6
|
diff-lcs (1.1.3)
|
14
7
|
faraday (0.8.8)
|
15
8
|
multipart-post (~> 1.2.0)
|
@@ -23,8 +16,8 @@ GEM
|
|
23
16
|
oauth2
|
24
17
|
hashie (2.0.5)
|
25
18
|
highline (1.6.20)
|
19
|
+
hpricot (0.8.6)
|
26
20
|
httpauth (0.2.0)
|
27
|
-
i18n (0.7.0)
|
28
21
|
jeweler (1.8.8)
|
29
22
|
builder
|
30
23
|
bundler (~> 1.0)
|
@@ -37,13 +30,10 @@ GEM
|
|
37
30
|
json (1.8.1)
|
38
31
|
jwt (0.1.8)
|
39
32
|
multi_json (>= 1.5)
|
40
|
-
|
41
|
-
mime-types (2.4.3)
|
42
|
-
minitest (5.5.0)
|
33
|
+
mime-types (1.25)
|
43
34
|
multi_json (1.8.2)
|
44
35
|
multi_xml (0.5.5)
|
45
36
|
multipart-post (1.2.0)
|
46
|
-
netrc (0.10.2)
|
47
37
|
nokogiri (1.5.10)
|
48
38
|
oauth2 (0.9.2)
|
49
39
|
faraday (~> 0.8)
|
@@ -52,17 +42,12 @@ GEM
|
|
52
42
|
multi_json (~> 1.0)
|
53
43
|
multi_xml (~> 0.5)
|
54
44
|
rack (~> 1.2)
|
55
|
-
pry (0.10.1)
|
56
|
-
coderay (~> 1.1.0)
|
57
|
-
method_source (~> 0.8.1)
|
58
|
-
slop (~> 3.4)
|
59
45
|
rack (1.5.2)
|
60
|
-
rake (10.1.
|
46
|
+
rake (10.1.0)
|
61
47
|
rdoc (3.12.2)
|
62
48
|
json (~> 1.4)
|
63
|
-
rest-client (1.7
|
64
|
-
mime-types (>= 1.16
|
65
|
-
netrc (~> 0.7)
|
49
|
+
rest-client (1.6.7)
|
50
|
+
mime-types (>= 1.16)
|
66
51
|
rspec (2.8.0)
|
67
52
|
rspec-core (~> 2.8.0)
|
68
53
|
rspec-expectations (~> 2.8.0)
|
@@ -71,16 +56,10 @@ GEM
|
|
71
56
|
rspec-expectations (2.8.0)
|
72
57
|
diff-lcs (~> 1.1.2)
|
73
58
|
rspec-mocks (2.8.0)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
json
|
79
|
-
rest-client (~> 1.6)
|
80
|
-
thor (0.19.1)
|
81
|
-
thread_safe (0.3.4)
|
82
|
-
tzinfo (1.2.2)
|
83
|
-
thread_safe (~> 0.1)
|
59
|
+
stock_quote (1.0.3)
|
60
|
+
hpricot
|
61
|
+
rest-client
|
62
|
+
thor (0.18.1)
|
84
63
|
|
85
64
|
PLATFORMS
|
86
65
|
ruby
|
@@ -88,9 +67,7 @@ PLATFORMS
|
|
88
67
|
DEPENDENCIES
|
89
68
|
bundler (~> 1.0)
|
90
69
|
jeweler (~> 1.8.7)
|
91
|
-
pry (~> 0.10)
|
92
70
|
rdoc (~> 3.12)
|
93
71
|
rspec (~> 2.8.0)
|
94
|
-
|
95
|
-
|
96
|
-
thor (~> 0.19)
|
72
|
+
stock_quote
|
73
|
+
thor
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Travis Loncar
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,25 +1,19 @@
|
|
1
|
-
|
1
|
+
Stock Quote CLI
|
2
|
+
===============
|
2
3
|
|
3
4
|
[![Build Status](https://travis-ci.org/tbloncar/stock_quote_cli.png?branch=master)](https://travis-ci.org/tbloncar/stock_quote_cli)
|
4
5
|
|
5
|
-
|
6
|
+
### Description
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
Update: Due to Google's sunsetting of iGoogle (and the associated endpoint from
|
10
|
-
which the stock_quote gem once fetched its data), the stock_quote gem has moved
|
11
|
-
to using the Yahoo! Finance API. This CLI gem has been updated to accommodate
|
12
|
-
the awesomely quick changes.
|
8
|
+
Stock Quote CLI is a Ruby gem that provides a command-line interface for fetching stock information from Google. It relies on the [stock_quote gem](https://github.com/tyrauber/stock_quote) for fetching real-time and historical data.
|
13
9
|
|
14
10
|
### Installation
|
15
11
|
|
16
|
-
|
12
|
+
Not yet available; but eventually:
|
17
13
|
|
18
|
-
|
19
|
-
gem install stock_quote_cli
|
20
|
-
```
|
14
|
+
gem install stock_quote_cli
|
21
15
|
|
22
|
-
### Usage
|
16
|
+
### Usage Details
|
23
17
|
|
24
18
|
You can use Stock Quote CLI to fetch real-time attributes of multiple stocks. Use the `stock` command in tandem with any of the available subcommands and stock symbols to fetch the relevant attribute(s).
|
25
19
|
|
@@ -27,55 +21,41 @@ You can use Stock Quote CLI to fetch real-time attributes of multiple stocks. Us
|
|
27
21
|
|
28
22
|
Get the latest price for the specified stock(s).
|
29
23
|
|
30
|
-
|
31
|
-
stock last goog yhoo aapl
|
32
|
-
```
|
24
|
+
stock last goog yhoo aapl
|
33
25
|
|
34
26
|
#### Open Price
|
35
27
|
|
36
28
|
Get the opening price for the specified stock(s) on the current day (or last trading day).
|
37
29
|
|
38
|
-
|
39
|
-
stock open znga
|
40
|
-
```
|
30
|
+
stock open znga
|
41
31
|
|
42
|
-
####
|
32
|
+
#### Yesterday's Closing Price
|
43
33
|
|
44
34
|
Get the closing price for the specified stock(s) on the previous trading day.
|
45
35
|
|
46
|
-
|
47
|
-
stock yclose amzn nflx
|
48
|
-
```
|
36
|
+
stock yclose amzn nflx
|
49
37
|
|
50
38
|
#### High Price
|
51
39
|
|
52
40
|
Get the high price for the specified stock(s) on the current day (or last trading day).
|
53
41
|
|
54
|
-
|
55
|
-
stock high lnkd
|
56
|
-
```
|
42
|
+
stock high lnkd
|
57
43
|
|
58
44
|
#### Low Price
|
59
45
|
|
60
46
|
Get the low price for the specified stock(s) on the current day (or last trading day).
|
61
47
|
|
62
|
-
|
63
|
-
stock low msft dell
|
64
|
-
```
|
48
|
+
stock low msft dell
|
65
49
|
|
66
50
|
#### Historical Data
|
67
51
|
|
68
|
-
Get historical data for a single stock. The default range is
|
52
|
+
Get historical data for a single stock. The default range is 10 days. The default value is the closing price. These can be specified using the `range` (aliased to `-r`) and `value` (aliased to `-v`) options, respectively.
|
69
53
|
|
70
|
-
|
71
|
-
stock history fb
|
72
|
-
```
|
54
|
+
stock history fb
|
73
55
|
|
74
56
|
The `range` (`-r`) option takes an integer. Use this to specify the number of trading days for which you'd like data.
|
75
57
|
|
76
|
-
|
77
|
-
stock history -r 15 fb
|
78
|
-
```
|
58
|
+
stock history -r 15 fb
|
79
59
|
|
80
60
|
The `value` (`-v`) option takes a string. Use this to specify the price value that you'd like to see in the output. You can choose from the following:
|
81
61
|
|
@@ -87,13 +67,11 @@ The `value` (`-v`) option takes a string. Use this to specify the price value th
|
|
87
67
|
|
88
68
|
Below, we fetch the high price for the Facebook stock for the past 15 days.
|
89
69
|
|
90
|
-
|
91
|
-
stock history -r 15 -v high fb
|
92
|
-
```
|
70
|
+
stock history -r 15 -v high fb
|
93
71
|
|
94
72
|
### License
|
95
73
|
|
96
|
-
Copyright (c)
|
74
|
+
Copyright (c) 2013 Travis Loncar
|
97
75
|
|
98
76
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
|
99
77
|
in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
data/Rakefile
CHANGED
@@ -22,6 +22,8 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
gem.email = "loncar.travis@gmail.com"
|
23
23
|
gem.authors = ["Travis Loncar"]
|
24
24
|
# dependencies defined in Gemfile
|
25
|
+
gem.add_dependency "thor", "~> 0.18.1"
|
26
|
+
gem.add_dependency "stock_quote", "~> 1.0.3"
|
25
27
|
end
|
26
28
|
Jeweler::RubygemsDotOrgTasks.new
|
27
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/lib/stock_quote_cli/cli.rb
CHANGED
@@ -1,124 +1,165 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "stock_quote"
|
3
|
+
require "stock_quote_cli/quote"
|
4
|
+
require "stock_quote_cli/history"
|
3
5
|
|
4
6
|
module StockQuoteCLI
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
89
|
-
|
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
|
-
|
7
|
+
class CLI < Thor
|
8
|
+
include StockQuoteCLI::Quote
|
9
|
+
include StockQuoteCLI::History
|
10
|
+
|
11
|
+
DEFAULT_RANGE = 10 # days
|
12
|
+
DEFAULT_VALUE = "close"
|
13
|
+
VALUE_OPTIONS = ["open", "high", "low", "close", "volume"]
|
14
|
+
|
15
|
+
desc "last SYMBOL [SYMBOL...]", "get LAST stock price for SYMBOL"
|
16
|
+
def last(symbol, *symbols)
|
17
|
+
stocks = stocks(symbol, symbols)
|
18
|
+
output_quote_messages(stocks, :last)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "high SYMBOL [SYMBOL...]", "get HIGH stock price for SYMBOL"
|
22
|
+
def high(symbol, *symbols)
|
23
|
+
stocks = stocks(symbol, symbols)
|
24
|
+
output_quote_messages(stocks, :high)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "low SYMBOL [SYMBOL...]", "get LOW stock price for SYMBOL"
|
28
|
+
def low(symbol, *symbols)
|
29
|
+
stocks = stocks(symbol, symbols)
|
30
|
+
output_quote_messages(stocks, :low)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "change SYMBOL [SYMBOL...]", "get CHANGE in stock price for SYMBOL"
|
34
|
+
def change(symbol, *symbols)
|
35
|
+
stocks = stocks(symbol, symbols)
|
36
|
+
output_quote_messages(stocks, :change)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "open SYMBOL [SYMBOL...]", "get OPEN stock price for SYMBOL"
|
40
|
+
def open(symbol, *symbols)
|
41
|
+
stocks = stocks(symbol, symbols)
|
42
|
+
output_quote_messages(stocks, :open)
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "yclose SYMBOL [SYMBOL...]", "get yesterday's closing (YCLOSE) stock price for SYMBOL"
|
46
|
+
def yclose(symbol, *symbols)
|
47
|
+
stocks = stocks(symbol, symbols)
|
48
|
+
output_quote_messages(stocks, :y_close)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "volume SYMBOL [SYMBOL...]", "get share VOLUME for SYMBOL"
|
52
|
+
def volume(symbol, *symbols)
|
53
|
+
stocks = stocks(symbol, symbols)
|
54
|
+
output_quote_messages(stocks, :volume)
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "history SYMBOL", "get HISTORY of stock price for SYMBOL"
|
58
|
+
method_option "range", aliases: "-r", type: :numeric, default: DEFAULT_RANGE, desc: "Specify the number of trading days for which to return stock price information."
|
59
|
+
method_option "value", aliases: "-v", type: :string, default: DEFAULT_VALUE, desc: "Specify the stock price value to retrieve for each date."
|
60
|
+
def history(symbol)
|
61
|
+
stock_history = get_stock_history(symbol)
|
62
|
+
trimmed_stock_history = trim_stock_history(stock_history, options['range'])
|
63
|
+
value = options['value']
|
64
|
+
output_history_messages(trimmed_stock_history, value, VALUE_OPTIONS, symbol)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def output_quote_messages(stocks, method_name)
|
70
|
+
puts
|
71
|
+
stocks.each do |stock|
|
72
|
+
if stock.response_code == 200
|
73
|
+
company = format_company(stock.company)
|
74
|
+
unless method_name == :volume
|
75
|
+
price = format_price(stock.send(method_name))
|
76
|
+
puts "#{company}: #{price}"
|
77
|
+
else
|
78
|
+
volume = format_volume(stock.send(method_name))
|
79
|
+
puts "#{company}: #{volume}"
|
80
|
+
end
|
81
|
+
else
|
82
|
+
puts bad_symbol_message(stock.symbol)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
puts
|
86
|
+
end
|
87
|
+
|
88
|
+
def output_history_messages(stock_history, method_name, method_options, symbol)
|
89
|
+
puts
|
90
|
+
unless stock_history.empty?
|
91
|
+
if method_options.include?(method_name)
|
92
|
+
puts format_title(method_name, symbol)
|
93
|
+
puts
|
94
|
+
stock_history.each do |day|
|
95
|
+
date = format_date(day.date)
|
96
|
+
unless method_name == "volume"
|
97
|
+
price = format_price(day.send(method_name))
|
98
|
+
puts "#{date}: #{price}"
|
99
|
+
else
|
100
|
+
volume = format_volume(day.send(method_name))
|
101
|
+
puts "#{date}: #{volume}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
else
|
105
|
+
puts bad_value_message(method_name)
|
106
|
+
end
|
107
|
+
else
|
108
|
+
puts bad_symbol_message(symbol)
|
109
|
+
end
|
110
|
+
puts
|
111
|
+
end
|
112
|
+
|
113
|
+
def bad_symbol_message(symbol)
|
114
|
+
"#{'No data available for:'.rjust(28)} #{symbol}".red
|
115
|
+
end
|
116
|
+
|
117
|
+
def bad_value_message(value_name)
|
118
|
+
"#{'Invalid value:'.rjust(28)} #{value_name}".red
|
119
|
+
end
|
120
|
+
|
121
|
+
def format_company(company)
|
122
|
+
company.green.rjust(40)
|
123
|
+
end
|
124
|
+
|
125
|
+
def format_date(date)
|
126
|
+
date.strftime('%m/%d/%Y').gsub("0013", "2013").green.rjust(40)
|
127
|
+
end
|
128
|
+
|
129
|
+
def format_price(price)
|
130
|
+
"$#{price.number_with_commas}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def format_volume(volume)
|
134
|
+
"#{volume.number_with_commas} shares"
|
135
|
+
end
|
136
|
+
|
137
|
+
def format_title(method_name, symbol)
|
138
|
+
"#{method_name.upcase.yellow} data for".rjust(38) + ": #{symbol.upcase.yellow}"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class Numeric
|
144
|
+
def number_with_commas
|
145
|
+
split_on_dot = to_s.split("\.")
|
146
|
+
whole = split_on_dot[0]
|
147
|
+
decimal = split_on_dot[1] || ""
|
148
|
+
char_array = whole.reverse.split(//)
|
149
|
+
whole_with_commas = char_array.each_with_index.map do |char, i|
|
150
|
+
if char_array.size > 3 && i % 3 == 0 && i > 0
|
151
|
+
"#{char},"
|
152
|
+
else
|
153
|
+
char
|
154
|
+
end
|
155
|
+
end.reverse.join("")
|
156
|
+
if decimal.size == 1
|
157
|
+
decimal = "#{decimal}0"
|
158
|
+
end
|
159
|
+
unless decimal == "" || decimal == "00"
|
160
|
+
"#{whole_with_commas}.#{decimal}"
|
161
|
+
else
|
162
|
+
"#{whole_with_commas}"
|
163
|
+
end
|
164
|
+
end
|
124
165
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module StockQuoteCLI
|
2
|
+
module Quote
|
3
|
+
private
|
4
|
+
|
5
|
+
def stocks(symbol, symbols)
|
6
|
+
symbol_string = symbol_string(symbol, symbols)
|
7
|
+
get_stocks(symbol_string)
|
8
|
+
end
|
9
|
+
|
10
|
+
def symbol_string(symbol, symbols)
|
11
|
+
symbols.unshift(symbol).join(", ")
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_stocks(symbol_string)
|
15
|
+
[] + StockQuote::Stock.quote(symbol_string)
|
16
|
+
end
|
17
|
+
|
18
|
+
class StockQuote::Stock
|
19
|
+
private
|
20
|
+
|
21
|
+
def to_ary
|
22
|
+
[] << self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/stock_quote_cli.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
require "stock_quote_cli/
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require "stock_quote_cli/cli"
|
2
|
+
|
3
|
+
class String
|
4
|
+
# color methods from https://github.com/pierot/stockery/blob/master/lib/stockery.rb
|
5
|
+
def red; color(self, "\e[31m"); end
|
6
|
+
def green; color(self, "\e[1m\e[32m"); end
|
7
|
+
def yellow; color(self, "\e[0;33m"); end
|
8
|
+
|
9
|
+
def color(text, color_code)
|
10
|
+
"#{color_code}#{text}\e[0m"
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
module StockQuoteCLI
|
4
|
-
describe CLI do
|
5
|
-
let(:cli) { CLI }
|
6
|
-
|
7
|
-
context 'history' do
|
8
|
-
it 'should accept a history method' do
|
9
|
-
$stdout.should_receive(:puts).at_least(10).times
|
10
|
-
cli.start(["history", "ebay"])
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should accept a range option' do
|
14
|
-
$stdout.should_receive(:puts).at_least(14).times
|
15
|
-
cli.start(["history", "-r", "20", "fb"])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
metadata
CHANGED
@@ -1,127 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stock_quote_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Loncar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: stock_quote
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.8.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.8.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: shoulda-matchers
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.7'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.7'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rdoc
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- -
|
59
|
+
- - ~>
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '3.12'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- -
|
66
|
+
- - ~>
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '3.12'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: bundler
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - ~>
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '1.0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- -
|
80
|
+
- - ~>
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '1.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: jeweler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- -
|
87
|
+
- - ~>
|
102
88
|
- !ruby/object:Gem::Version
|
103
89
|
version: 1.8.7
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- -
|
94
|
+
- - ~>
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: 1.8.7
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: thor
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ~>
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
118
|
-
type: :
|
103
|
+
version: 0.18.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.18.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: stock_quote
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.0.3
|
118
|
+
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 1.0.3
|
125
125
|
description: A Ruby gem that provides a command-line interface for fetching stock
|
126
126
|
information.
|
127
127
|
email: loncar.travis@gmail.com
|
@@ -129,25 +129,25 @@ executables:
|
|
129
129
|
- stock
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files:
|
132
|
+
- LICENSE.txt
|
132
133
|
- README.md
|
133
134
|
files:
|
134
|
-
-
|
135
|
-
-
|
135
|
+
- .document
|
136
|
+
- .rspec
|
137
|
+
- .travis.yml
|
136
138
|
- Gemfile
|
137
139
|
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
138
141
|
- README.md
|
139
142
|
- Rakefile
|
140
143
|
- VERSION
|
141
144
|
- bin/stock
|
142
|
-
- demo.gif
|
143
145
|
- lib/stock_quote_cli.rb
|
144
|
-
- lib/stock_quote_cli/api.rb
|
145
146
|
- lib/stock_quote_cli/cli.rb
|
146
|
-
- lib/stock_quote_cli/
|
147
|
-
- lib/stock_quote_cli/
|
147
|
+
- lib/stock_quote_cli/history.rb
|
148
|
+
- lib/stock_quote_cli/quote.rb
|
148
149
|
- spec/spec_helper.rb
|
149
150
|
- spec/stock_quote_cli_spec.rb
|
150
|
-
- stock_quote_cli.gemspec
|
151
151
|
homepage: http://github.com/tbloncar/stock_quote_cli
|
152
152
|
licenses:
|
153
153
|
- MIT
|
@@ -158,17 +158,17 @@ require_paths:
|
|
158
158
|
- lib
|
159
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
160
160
|
requirements:
|
161
|
-
- -
|
161
|
+
- - '>='
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
165
|
requirements:
|
166
|
-
- -
|
166
|
+
- - '>='
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.0.3
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: A Ruby gem that provides a command-line interface for fetching stock information.
|
data/demo.gif
DELETED
Binary file
|
data/lib/stock_quote_cli/api.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require "stock_quote"
|
2
|
-
|
3
|
-
module StockQuoteCLI
|
4
|
-
class API
|
5
|
-
def self.stock_history(symbol, range)
|
6
|
-
end_date = Date.today
|
7
|
-
start_date = end_date - range
|
8
|
-
StockQuote::Stock.history(symbol, start_date, end_date)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.stocks_info(symbols)
|
12
|
-
[] + StockQuote::Stock.quote(symbols.join(", "))
|
13
|
-
end
|
14
|
-
|
15
|
-
class StockQuote::Stock
|
16
|
-
private
|
17
|
-
|
18
|
-
def to_ary
|
19
|
-
[] << self
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/stock_quote_cli/text.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module StockQuoteCLI
|
2
|
-
class Text
|
3
|
-
class << self
|
4
|
-
# color methods from https://github.com/pierot/stockery/blob/master/lib/stockery.rb
|
5
|
-
def red(str); color(str, "\e[31m"); end
|
6
|
-
def green(str); color(str, "\e[1m\e[32m"); end
|
7
|
-
def yellow(str); color(str, "\e[0;33m"); end
|
8
|
-
|
9
|
-
def number_with_commas(n)
|
10
|
-
int, dec = n.to_s.split(".")
|
11
|
-
int.chars.reverse.each_slice(3).reduce("") { |m, s|
|
12
|
-
m + s.join + (s.size == 3 ? "," : "")
|
13
|
-
}.reverse.gsub(/^,/, '') + (dec ? ".#{dec}" : "")
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def color(text, color_code)
|
19
|
-
"#{color_code}#{text}\e[0m"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/stock_quote_cli.gemspec
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: stock_quote_cli 0.0.0 ruby lib
|
6
|
-
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = "stock_quote_cli"
|
9
|
-
s.version = "0.0.0"
|
10
|
-
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Travis Loncar"]
|
14
|
-
s.date = "2016-01-01"
|
15
|
-
s.description = "A Ruby gem that provides a command-line interface for fetching stock information."
|
16
|
-
s.email = "loncar.travis@gmail.com"
|
17
|
-
s.executables = ["stock"]
|
18
|
-
s.extra_rdoc_files = [
|
19
|
-
"README.md"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".rspec",
|
23
|
-
".travis.yml",
|
24
|
-
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
|
-
"README.md",
|
27
|
-
"Rakefile",
|
28
|
-
"VERSION",
|
29
|
-
"bin/stock",
|
30
|
-
"demo.gif",
|
31
|
-
"lib/stock_quote_cli.rb",
|
32
|
-
"lib/stock_quote_cli/api.rb",
|
33
|
-
"lib/stock_quote_cli/cli.rb",
|
34
|
-
"lib/stock_quote_cli/text.rb",
|
35
|
-
"lib/stock_quote_cli/version.rb",
|
36
|
-
"spec/spec_helper.rb",
|
37
|
-
"spec/stock_quote_cli_spec.rb",
|
38
|
-
"stock_quote_cli.gemspec"
|
39
|
-
]
|
40
|
-
s.homepage = "http://github.com/tbloncar/stock_quote_cli"
|
41
|
-
s.licenses = ["MIT"]
|
42
|
-
s.rubygems_version = "2.4.8"
|
43
|
-
s.summary = "A Ruby gem that provides a command-line interface for fetching stock information."
|
44
|
-
|
45
|
-
if s.respond_to? :specification_version then
|
46
|
-
s.specification_version = 4
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_runtime_dependency(%q<thor>, ["~> 0.19"])
|
50
|
-
s.add_runtime_dependency(%q<stock_quote>, ["~> 1.2"])
|
51
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
52
|
-
s.add_development_dependency(%q<shoulda-matchers>, ["~> 2.7"])
|
53
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
55
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
56
|
-
s.add_development_dependency(%q<pry>, ["~> 0.10"])
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<thor>, ["~> 0.19"])
|
59
|
-
s.add_dependency(%q<stock_quote>, ["~> 1.2"])
|
60
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
-
s.add_dependency(%q<shoulda-matchers>, ["~> 2.7"])
|
62
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
64
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
65
|
-
s.add_dependency(%q<pry>, ["~> 0.10"])
|
66
|
-
end
|
67
|
-
else
|
68
|
-
s.add_dependency(%q<thor>, ["~> 0.19"])
|
69
|
-
s.add_dependency(%q<stock_quote>, ["~> 1.2"])
|
70
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
71
|
-
s.add_dependency(%q<shoulda-matchers>, ["~> 2.7"])
|
72
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
73
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
74
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
75
|
-
s.add_dependency(%q<pry>, ["~> 0.10"])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|