Class: CryptoCompare::CLI
- Inherits:
-
Object
- Object
- CryptoCompare::CLI
- Defined in:
- lib/crypto_compare/cli.rb
Instance Method Summary collapse
- #another_or_exit ⇒ Object
- #call ⇒ Object
- #display_results ⇒ Object
- #set_base_currency ⇒ Object
- #set_crypto_currency_and_data ⇒ Object
- #set_infinite_precision ⇒ Object
- #set_variables ⇒ Object
Instance Method Details
#another_or_exit ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/crypto_compare/cli.rb', line 68 def another_or_exit puts "Convert another? y/n" input = gets.downcase.chomp case input when "y", "yes" call when "n", "no" puts "Thank you for using CryptoCompare!" puts "Goodbye." exit else puts "Incorrect input." another_or_exit end end |
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/crypto_compare/cli.rb', line 7 def call @s = CryptoCompare::Scraper.new Money.default_bank = Money::Bank::GoogleCurrency.new set_crypto_currency_and_data set_variables set_infinite_precision set_base_currency display_results another_or_exit end |
#display_results ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/crypto_compare/cli.rb', line 58 def display_results puts "-"*20 puts "Crypto Currency: #{@crypto_currency.name}" puts "Current Price: #{@price.exchange_to(@base_currency).symbol}#{@price.exchange_to(@base_currency)} #{@price.exchange_to(@base_currency).currency.iso_code}" puts "Market Cap: #{@cap.exchange_to(@base_currency).symbol}#{@cap.exchange_to(@base_currency)} #{@cap_value} #{@cap.exchange_to(@base_currency).currency.iso_code}" puts "Circulating Supply: #{@crypto_currency.circulating_supply}" puts "Percent Change (24 hrs): #{@crypto_currency.percent_change} #{@change_direction}" puts "-"*20 end |
#set_base_currency ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/crypto_compare/cli.rb', line 48 def set_base_currency puts "Please enter your fiat currency of interest's ISO code (e.g. USD, CAD, GBP, JPY, etc.):" @base_currency = gets.upcase.chomp.to_sym if Money::Currency.include?(@base_currency) == false puts "No such fiat currency found." set_base_currency end end |
#set_crypto_currency_and_data ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/crypto_compare/cli.rb', line 20 def set_crypto_currency_and_data puts "Please enter your crypto currency of interest (e.g. bitcoin, ethereum, dogecoin, etc.)" puts "or enter the number (e.g. 1) or name (e.g. bitcoin) of a currency from the top 10 list below:" CryptoCompare::CryptoCurrency.make_crypto_from_list(@s.get_list(@s.page), @s) CryptoCompare::CryptoCurrency.all.each_with_index {|crypto, index| puts "#{index+1}. #{crypto.name}"} @crypto_currency = gets.downcase.chomp @crypto_currency = @s.get_list(@s.page)[@crypto_currency.to_i-1] if @crypto_currency.to_i >= 1 @data = @s.get_attributes(@crypto_currency, @s.page) if @data["price"] == "" puts "No such crypto currency found." set_crypto_currency_and_data end end |
#set_infinite_precision ⇒ Object
44 45 46 |
# File 'lib/crypto_compare/cli.rb', line 44 def set_infinite_precision @crypto_currency.price.to_f < 1 ? Money.infinite_precision = true : Money.infinite_precision = false end |
#set_variables ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/crypto_compare/cli.rb', line 35 def set_variables @crypto_currency = CryptoCompare::CryptoCurrency.new(@data) @price = Money.new("#{@crypto_currency.price}".delete("$").to_f*100, "USD") @cap = Money.new("#{@crypto_currency.market_cap}".delete("$").to_f*100, "USD") @cap_value = @crypto_currency.market_cap.delete("$,").length >= 10 ? "billion" : "million" @volume = Money.new("#{@crypto_currency.volume}".delete("$").to_f*100, "USD") @change_direction = @crypto_currency.percent_change[0] == "-" ? "v" : "^" end |