coingecko 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b2b6a7fa8f8e6a34ce9744a9a907527e7095535344c6d6aeeceb214960ed3fe
4
- data.tar.gz: e5c630b312a1ff17c7a023966e74d4ea02de870713c7cb681b8c58f97ee832b9
3
+ metadata.gz: aef09806691f80769a8ac2c134030e4ae6c02e9ed36aafcbfbb77e8bd6a0f457
4
+ data.tar.gz: 03334057d18f4be0604983444433eb1623e13b3649278a4503e5de79f211d2ef
5
5
  SHA512:
6
- metadata.gz: 1303471a5da3056fd45f897ed5aeb3654242ae32b9ac04802a267c81d8eecf2905be5d3ade877edc974ff253c009ca1580176ce750e3224a22669fdd8107226f
7
- data.tar.gz: 48eb2b5a7c11b5c87d40d5678866c9a77f427b3349acc8e6d1ccd589b344b1ac6e4940ee213e16cca54324d276ff56d789762703ad0640e8bba2baa324a6fc67
6
+ metadata.gz: 92a8c8eeaa6d438e6a7f5b29bef8f64bd80c283bb3318afa64754f9fc93005ead7c81bc5b0c0ac4de6c7e82dcbea3e2881ca597a62453b55da13962a1ad28a74
7
+ data.tar.gz: a1d2f32296c36207b7fbe41d3980021a5b218aaebbc1d58b4a30614fb336bee72ffb632b134a07083b9f74d56c28894cc4b969ec5b9d72ac5e54f8d905622d68
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coingecko (0.1.1)
4
+ coingecko (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Coingecko - A CoinGecko API with CLI Interface
1
+ # Coingecko - A CoinGecko API with CLI
2
2
 
3
3
  Pushes all coin data from Coingecko API. Also lists top 100 coins and overall market info.
4
4
 
@@ -31,10 +31,10 @@ Coingecko::Global.new_from_global
31
31
  #Returns object with ALL available coins with id, symbol, name
32
32
  Coingecko::Global.get_all_coins_list
33
33
 
34
- #Returns top 100 coins objects only with id, symbol, name, market_cap_rank, last_updated. Default currency is "usd"
34
+ #Returns top 100 coins objects only with id, symbol, name, market_cap_rank, last_updated. Default currency is "usd" if no currency given. E.g.
35
35
  Coingecko::Coin.new_from_top_100
36
36
 
37
- #Returns a particular coin object with ALL avaiable data from Coingecko. It needs an id as an argument. Example:
37
+ #Returns a particular coin object with ALL avaiable data from Coingecko. It needs an id as an argument. E.g.
38
38
  Coingecko::Coin.get_coin("bitcoin")
39
39
 
40
40
 
@@ -1,3 +1,5 @@
1
+
2
+ include Concerns::Findable
1
3
  class Coingecko::CLI
2
4
  @@commands = ["ls", "list", "b", "back", "menu", "m", "q", "quit", "exit", "exit!", "find", "f"]
3
5
 
@@ -137,29 +139,34 @@ class Coingecko::CLI
137
139
 
138
140
  def find
139
141
  puts "Which coin would you like to find?"
140
- input = gets.strip.downcase
141
-
142
- Coingecko::Global.get_all_coins_list
143
- all_coins_basic = Coingecko::Global.all_coins_list
144
- returned_id = ""
145
- all_coins_basic.each do |coin|
146
- if coin.name.strip.downcase == input
147
- returned_id = coin.id
148
- end
149
- end
150
-
151
- if !returned_id.empty?
152
- sleep 1
153
- puts "\nCoin match found!\n\n"
154
- sleep 2
155
- print_coin(returned_id)
156
- else
157
- sleep 1
158
- puts "\nSorry. There was no coin match for '#{input}'.\n\n"
159
- sleep 2
160
- another_selection?
161
- end
142
+ input = gets.chomp.downcase
143
+ coin = find_by_name(input) || guess_by_name(input)
144
+ case
145
+ when coin.class == Coingecko::Global #found with pry to see what class it is
146
+ sleep 1
147
+ puts "\nCoin match found!\n\n"
148
+ sleep 2
149
+ print_coin(coin.id)
150
+ when coin.class == Array && coin.length > 0
151
+ sleep 1
152
+ puts "\nMore than one possible match found. Please see below..\n\n"
153
+ sleep 2
154
+ coin.each_with_index { |o, i| puts "#{i + 1} - #{o.name}" }
155
+ puts "\nIf one of the coins provided is what you're looking for, please type 1 - #{coin.length}. Else type menu to go back.\n\n"
156
+ answer = gets.chomp
157
+ if answer.to_i > 0 #if string converted to_i will have value of 0
158
+ id = coin[answer.to_i - 1].id
159
+ print_coin(id)
160
+ else
161
+ check_selection(answer)
162
+ end
163
+ else
164
+ sleep 1
165
+ puts "\nSorry. There was no coin match for '#{input}'.\n\n"
166
+ sleep 2
167
+ another_selection?
162
168
 
169
+ end
163
170
  end
164
171
 
165
172
  def print_coin(id, currency="usd")
@@ -1,3 +1,3 @@
1
1
  module Coingecko
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ module Concerns
2
+ module Findable
3
+ def find_by_name(input)
4
+ Coingecko::Global.get_all_coins_list
5
+ Coingecko::Global.all_coins_list.detect {|coin| coin.name.strip.downcase == input }
6
+ end
7
+
8
+ def guess_by_name(input)
9
+ Coingecko::Global.get_all_coins_list
10
+ Coingecko::Global.all_coins_list.filter {|coin| coin.name.strip.downcase.include? input }
11
+ end
12
+ end
13
+ end
@@ -4,8 +4,9 @@ require 'nokogiri'
4
4
  require 'json'
5
5
  require 'terminal-table'
6
6
 
7
- require_relative "coingecko/cli/version"
8
- require_relative "coingecko/cli"
9
- require_relative "coingecko/api"
10
- require_relative "coingecko/coin"
11
- require_relative "coingecko/global"
7
+ require_relative 'coingecko/concerns/findable'
8
+ require_relative 'coingecko/cli/version'
9
+ require_relative 'coingecko/cli'
10
+ require_relative 'coingecko/api'
11
+ require_relative 'coingecko/coin'
12
+ require_relative 'coingecko/global'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coingecko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Felipe Bohorquez'"
@@ -132,6 +132,7 @@ files:
132
132
  - lib/coingecko/cli.rb
133
133
  - lib/coingecko/cli/version.rb
134
134
  - lib/coingecko/coin.rb
135
+ - lib/coingecko/concerns/findable.rb
135
136
  - lib/coingecko/global.rb
136
137
  - lib/environment.rb
137
138
  homepage: https://github.com/fbohz/coingecko.git