crypto_market 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/crypto-market +7 -0
- data/bin/setup +8 -0
- data/crypto_market.gemspec +29 -0
- data/lib/crypto_market/api.rb +17 -0
- data/lib/crypto_market/cli.rb +149 -0
- data/lib/crypto_market/coin.rb +28 -0
- data/lib/crypto_market/currencies.rb +97 -0
- data/lib/crypto_market/version.rb +3 -0
- data/lib/crypto_market.rb +18 -0
- data/notes.md +37 -0
- data/spec.md +7 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3deabc7efffd28e875baa3fe5964490dafa52459
|
4
|
+
data.tar.gz: 2271e5356fe539382fab9a35bd9c90f3a8da2602
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3471302a044365464b1034033eca8c38e81021226f605916d01ca5a342dddecfa19c89e57aaa236e9814579cb424f7338209b3f8a5782627ba3b330b4fd216c2
|
7
|
+
data.tar.gz: 75cd81c8319ebd4b274990fa829131167007722a73ec6faa25c88deaf5e46a2d39ae3525bff09a9b9678153139b79733143b5ad357381159e0256fbfc0100455
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at s.ojling@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Sam Ojling
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# CryptoMarket
|
2
|
+
|
3
|
+
Welcome to Crypto Market Gem, this gem will display the top 100 crypto currencies gathered from coinmarketcap.com. The data is updated every 5 minutes. You will be able to sort the coins based on change, price and get currency value from currencies across the world.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'crypto_market'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install crypto_market
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To run the CLI app just typ `crypto-market` in your terminal after you've installed the gem.
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/scarsam/crypto_market. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the CryptoMarket project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/scarsam/crypto_market/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "crypto_market"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/crypto-market
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "crypto_market/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "crypto_market"
|
8
|
+
spec.version = CryptoMarket::VERSION
|
9
|
+
spec.authors = ["Sam Ojling"]
|
10
|
+
spec.email = ["s.ojling@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CLI that display data from coinmarketcap.com}
|
13
|
+
spec.description = %q{Crypto Market CLI will display data from the top 100 cryptocurrencies, it will let you sort data based on price and most postivive/negative changed coins}
|
14
|
+
spec.homepage = "https://github.com/scarsam/crypto_market"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = "crypto-market"
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
28
|
+
spec.add_runtime_dependency 'terminal-table', '~> 1.8'
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CryptoMarket::Api
|
2
|
+
|
3
|
+
def self.fetch_coin_data
|
4
|
+
url = URI('https://coinmarketcap-nexuist.rhcloud.com/api/all')
|
5
|
+
response = Net::HTTP.get(url)
|
6
|
+
JSON.parse(response)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.validate_coin_data
|
10
|
+
fetch_coin_data.reject do |coin_name, coin_attributes|
|
11
|
+
coin_attributes.any? do |attribute, attribute_value|
|
12
|
+
attribute_value == '?' || attribute_value.nil?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
class CryptoMarket::CLI
|
2
|
+
include CryptoMarket
|
3
|
+
attr_accessor :currencies
|
4
|
+
|
5
|
+
# Initialize the CLI with an instance of all currencies
|
6
|
+
def initialize
|
7
|
+
@currencies = CryptoMarket::Currencies.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# Run command to start the program
|
11
|
+
def run
|
12
|
+
currencies.run
|
13
|
+
puts ascii_welcome
|
14
|
+
navigation
|
15
|
+
end
|
16
|
+
|
17
|
+
# Greeting message
|
18
|
+
def greeting
|
19
|
+
<<-DOC
|
20
|
+
Welcome to the Crypto Market
|
21
|
+
All the prices are updated every 5 minutes
|
22
|
+
Enter a number to navigate
|
23
|
+
DOC
|
24
|
+
end
|
25
|
+
|
26
|
+
def enter_valid_input_msg
|
27
|
+
puts 'Enter a correct number from the list'
|
28
|
+
end
|
29
|
+
|
30
|
+
def enter_input_msg
|
31
|
+
print 'Enter a number: '
|
32
|
+
end
|
33
|
+
|
34
|
+
# User navigation
|
35
|
+
def navigation
|
36
|
+
table = terminal_table do |t|
|
37
|
+
t.title = greeting
|
38
|
+
t.add_row [1, 'To see the list of supported coins']
|
39
|
+
t.add_row [2, 'Sort by price']
|
40
|
+
t.add_row [3, 'Sort by price change']
|
41
|
+
t.add_row [4, 'Get more information about a specific coin']
|
42
|
+
t.add_row [5, 'To exit the program']
|
43
|
+
t.style = { all_separators: true }
|
44
|
+
end
|
45
|
+
puts table
|
46
|
+
enter_input_msg
|
47
|
+
input = gets.strip.to_i
|
48
|
+
loop do
|
49
|
+
case input
|
50
|
+
when 1
|
51
|
+
currencies.print_coin_names
|
52
|
+
nested_menu
|
53
|
+
when 2
|
54
|
+
currencies.print_sorted_prices
|
55
|
+
nested_menu
|
56
|
+
when 3
|
57
|
+
table = terminal_table do |t|
|
58
|
+
t.title = 'Select a number'
|
59
|
+
t.add_row [1, 'To see (+)positive price changes']
|
60
|
+
t.add_row [2, 'To see (-)negative price changes']
|
61
|
+
t.add_row [3, 'To see both negative and positive']
|
62
|
+
t.style = { all_separators: true }
|
63
|
+
end
|
64
|
+
input = nil
|
65
|
+
until input == 1 || input == 2 || input == 3
|
66
|
+
puts table
|
67
|
+
enter_input_msg
|
68
|
+
input = gets.to_i
|
69
|
+
if input == 1
|
70
|
+
currencies.print_sorted_changes('positive')
|
71
|
+
nested_menu
|
72
|
+
elsif input == 2
|
73
|
+
currencies.print_sorted_changes('negative')
|
74
|
+
nested_menu
|
75
|
+
elsif input == 3
|
76
|
+
currencies.print_sorted_changes
|
77
|
+
nested_menu
|
78
|
+
else
|
79
|
+
enter_valid_input_msg
|
80
|
+
end
|
81
|
+
end
|
82
|
+
when 4
|
83
|
+
coin_search
|
84
|
+
nested_menu
|
85
|
+
when 5
|
86
|
+
puts "Goodbye you're now closing Crypto Market!"
|
87
|
+
exit
|
88
|
+
else
|
89
|
+
enter_valid_input_msg
|
90
|
+
navigation
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Nested menu that can be accessed inside the main navigation
|
97
|
+
def nested_menu
|
98
|
+
table = terminal_table do |t|
|
99
|
+
t.title = 'Select a number'
|
100
|
+
t.add_row [1, 'To get more information about a specific coin']
|
101
|
+
t.add_row [2, 'To return to the menu']
|
102
|
+
t.style = { all_separators: true }
|
103
|
+
end
|
104
|
+
puts table
|
105
|
+
enter_input_msg
|
106
|
+
input = gets.strip.to_i
|
107
|
+
case input
|
108
|
+
when 1
|
109
|
+
coin_search
|
110
|
+
nested_menu
|
111
|
+
when 2
|
112
|
+
navigation
|
113
|
+
else
|
114
|
+
enter_valid_input_msg
|
115
|
+
nested_menu
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Search for specific name for a coin and return information about it
|
120
|
+
def coin_search
|
121
|
+
currencies.print_coin_names
|
122
|
+
enter_input_msg
|
123
|
+
input = gets.strip.to_i
|
124
|
+
if currencies.find_by_number(input).nil?
|
125
|
+
enter_valid_input_msg
|
126
|
+
coin_search
|
127
|
+
else
|
128
|
+
currencies.find_by_number(input).attributes
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Ascii welcome message
|
133
|
+
def ascii_welcome
|
134
|
+
<<-'HEREDOC'
|
135
|
+
|
136
|
+
/$$$$$$ /$$ /$$ /$$ /$$ /$$
|
137
|
+
/$$__ $$ | $$ | $$$ /$$$ | $$ | $$
|
138
|
+
| $$ \__/ /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ | $$$$ /$$$$ /$$$$$$ /$$$$$$ | $$ /$$ /$$$$$$ /$$$$$$
|
139
|
+
| $$ /$$__ $$| $$ | $$ /$$__ $$|_ $$_/ /$$__ $$ | $$ $$/$$ $$ |____ $$ /$$__ $$| $$ /$$/ /$$__ $$|_ $$_/
|
140
|
+
| $$ | $$ \__/| $$ | $$| $$ \ $$ | $$ | $$ \ $$ | $$ $$$| $$ /$$$$$$$| $$ \__/| $$$$$$/ | $$$$$$$$ | $$
|
141
|
+
| $$ $$| $$ | $$ | $$| $$ | $$ | $$ /$$| $$ | $$ | $$\ $ | $$ /$$__ $$| $$ | $$_ $$ | $$_____/ | $$ /$$
|
142
|
+
| $$$$$$/| $$ | $$$$$$$| $$$$$$$/ | $$$$/| $$$$$$/ | $$ \/ | $$| $$$$$$$| $$ | $$ \ $$| $$$$$$$ | $$$$/
|
143
|
+
\______/ |__/ \____ $$| $$____/ \___/ \______/ |__/ |__/ \_______/|__/ |__/ \__/ \_______/ \___/
|
144
|
+
/$$ | $$| $$
|
145
|
+
| $$$$$$/| $$
|
146
|
+
\______/ |__/
|
147
|
+
|
148
|
+
HEREDOC
|
149
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Crypto Coin belongs to Crypto Currencies
|
2
|
+
# Responsible for handling all of the Crypto Coin information
|
3
|
+
|
4
|
+
class CryptoMarket::Coin
|
5
|
+
include CryptoMarket
|
6
|
+
attr_accessor :name, :price, :change
|
7
|
+
|
8
|
+
# Instantiate Coin with the attributes below, adds + sign for positive change numbers
|
9
|
+
def initialize(name, price, change)
|
10
|
+
@name = name
|
11
|
+
@price = price
|
12
|
+
@change = change.to_f > 0 ? "+#{change}" : change
|
13
|
+
end
|
14
|
+
|
15
|
+
# Prints out the coin attributes for the Coin object with terminal-table gem
|
16
|
+
def attributes
|
17
|
+
table = terminal_table do |t|
|
18
|
+
t.title = name.upcase
|
19
|
+
t.add_row ["Change:", "#{change}%"]
|
20
|
+
price.each do |currency, price|
|
21
|
+
t.add_row [currency.upcase, price.to_f.round(2)]
|
22
|
+
end
|
23
|
+
t.style = { all_separators: true, width: 30 }
|
24
|
+
end
|
25
|
+
puts table
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Crypto Currencies is having many Crypto Coins
|
2
|
+
|
3
|
+
class CryptoMarket::Currencies
|
4
|
+
include CryptoMarket
|
5
|
+
attr_accessor :coins
|
6
|
+
# Store all the currencies in an Array
|
7
|
+
def initialize
|
8
|
+
@coin_data = CryptoMarket::Api.validate_coin_data
|
9
|
+
@coins = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Instantiates new coins from Coin class with attributes specified from coin_attribues method
|
13
|
+
def run
|
14
|
+
create_coins_from_attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
# Instantiates a new Coin based on hash that gets passed in and set it's attributes
|
18
|
+
def create_coin(coin)
|
19
|
+
name = coin['symbol']
|
20
|
+
price = coin['price']
|
21
|
+
change = coin['change']
|
22
|
+
CryptoMarket::Coin.new(name, price, change).tap do |new_coin|
|
23
|
+
coins << new_coin
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Call the create_coin method for each Coin hash
|
28
|
+
def create_coins_from_attributes
|
29
|
+
coin_attributes.each do |coin|
|
30
|
+
create_coin(coin)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns an Array with hashes containing selected information for each Coin
|
35
|
+
def coin_attributes
|
36
|
+
@coin_data.map do |coin_name, coin_attributes|
|
37
|
+
coin_attributes.select do |attribute, attribute_value|
|
38
|
+
attribute == 'symbol' || attribute == 'price' || attribute == 'change'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns an instance of Coin for the specific Coin that user is looking for
|
44
|
+
def find_by_number(input)
|
45
|
+
coins[input - 1]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Ranks the coins from based on their USD price
|
49
|
+
def sort_by_price
|
50
|
+
coins.sort_by { |coin| coin.price['usd'] }.reverse
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return sorted Array based on user input (positive, negative or default)
|
54
|
+
def sort_by_change(input)
|
55
|
+
if input == 'positive'
|
56
|
+
coins.select { |coin| coin.change.to_f > 0 }.sort_by { |coin| coin.change.to_f }.reverse
|
57
|
+
elsif input == 'negative'
|
58
|
+
coins.select { |coin| coin.change.to_f < 0 }.sort_by { |coin| coin.change.to_f }
|
59
|
+
else
|
60
|
+
coins.sort_by { |coin| coin.change.to_f }.reverse
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Prints out the price for all Coin objects with terminal-table gem
|
65
|
+
def print_sorted_prices
|
66
|
+
sort_by_price.each do |coin|
|
67
|
+
table = terminal_table do |t|
|
68
|
+
t.add_row [coin.name, "$#{coin.price['usd'].to_f.round(4)}"]
|
69
|
+
t.style = { all_separators: true, width: 40 }
|
70
|
+
end
|
71
|
+
puts table
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Prints out the change for all Coin objects with terminal-table gem
|
76
|
+
def print_sorted_changes(input = nil)
|
77
|
+
sort_by_change(input).each do |coin|
|
78
|
+
table = terminal_table do |t|
|
79
|
+
t.add_row [coin.name, "#{coin.change}%"]
|
80
|
+
t.style = { all_separators: true, width: 40 }
|
81
|
+
end
|
82
|
+
puts table
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Prints out the names for all Coin objects with terminal-table gem
|
87
|
+
def print_coin_names
|
88
|
+
coins.each_with_index do |coin, index|
|
89
|
+
table = terminal_table do |t|
|
90
|
+
t.add_row [index + 1, coin.name]
|
91
|
+
t.style = { all_separators: true, width: 15 }
|
92
|
+
end
|
93
|
+
puts table
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Gem requirements
|
2
|
+
require 'pry'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'terminal-table'
|
6
|
+
require "crypto_market/version"
|
7
|
+
require "crypto_market/cli"
|
8
|
+
require "crypto_market/currencies"
|
9
|
+
require "crypto_market/coin"
|
10
|
+
require "crypto_market/api"
|
11
|
+
|
12
|
+
# Looked how the owner instantiated a single Object on Github
|
13
|
+
# https://github.com/tj/terminal-table/blob/master/lib/terminal-table/table_helper.rb
|
14
|
+
module CryptoMarket
|
15
|
+
def terminal_table(headings = [], *rows, &block)
|
16
|
+
Terminal::Table.new :headings => headings.to_a, :rows => rows, &block
|
17
|
+
end
|
18
|
+
end
|
data/notes.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#### About
|
2
|
+
Crypto-Currency Market CLI Gem
|
3
|
+
|
4
|
+
*Price updated every 30 minutes*
|
5
|
+
|
6
|
+
- Docs: https://coinmarketcap-nexuist.rhcloud.com/api/all
|
7
|
+
|
8
|
+
#### User Interface
|
9
|
+
1. List Crypto-Currencies
|
10
|
+
- Welcome message
|
11
|
+
- Navigation
|
12
|
+
- List all currencies
|
13
|
+
- Sort by pricing
|
14
|
+
- Sort by changed
|
15
|
+
- Get more information about specific coin
|
16
|
+
- Exit
|
17
|
+
2. Pick one to get more information about
|
18
|
+
- Type name of coin you want more information about
|
19
|
+
- Name - name
|
20
|
+
- Price - Price
|
21
|
+
- Change - Past hour price change
|
22
|
+
3. Sort by pricing
|
23
|
+
- Display all coins based on their price (Highest > lowest)
|
24
|
+
4. Sort by changes
|
25
|
+
- Sort by positive changed
|
26
|
+
- See positive changed coins
|
27
|
+
- Sort by negative changed
|
28
|
+
- See negative changed coins
|
29
|
+
- See all
|
30
|
+
- See all coins
|
31
|
+
5. Ask user to perform another action
|
32
|
+
- Loop menu
|
33
|
+
|
34
|
+
Object Relationship
|
35
|
+
|
36
|
+
Rule of thumb:
|
37
|
+
A method that acts on a single object should be an instance method. A method that acts on a group of similar objects should be a class method.
|
data/spec.md
ADDED
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crypto_market
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Ojling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: terminal-table
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
description: Crypto Market CLI will display data from the top 100 cryptocurrencies,
|
84
|
+
it will let you sort data based on price and most postivive/negative changed coins
|
85
|
+
email:
|
86
|
+
- s.ojling@gmail.com
|
87
|
+
executables:
|
88
|
+
- crypto-market
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/crypto-market
|
102
|
+
- bin/setup
|
103
|
+
- crypto_market.gemspec
|
104
|
+
- lib/crypto_market.rb
|
105
|
+
- lib/crypto_market/api.rb
|
106
|
+
- lib/crypto_market/cli.rb
|
107
|
+
- lib/crypto_market/coin.rb
|
108
|
+
- lib/crypto_market/currencies.rb
|
109
|
+
- lib/crypto_market/version.rb
|
110
|
+
- notes.md
|
111
|
+
- spec.md
|
112
|
+
homepage: https://github.com/scarsam/crypto_market
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.6.12
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: CLI that display data from coinmarketcap.com
|
136
|
+
test_files: []
|