Class: CepC
- Inherits:
-
Object
- Object
- CepC
- Defined in:
- lib/cepc_coinbase.rb
Overview
Cep Calculator
Instance Attribute Summary collapse
-
#exchange_values ⇒ Object
writeonly
Sets the attribute exchange_values.
Instance Method Summary collapse
- #amount_of(currency, amount, printable = false) ⇒ Object
- #exchange_diff(curr1, curr2, printable = false) ⇒ Object
-
#initialize(params = {}) ⇒ CepC
constructor
A new instance of CepC.
- #price_of(currency) ⇒ Object
- #print_day_left ⇒ Object
- #print_exchange_amounts(arr = @exchange_values) ⇒ Object
- #print_n_day_earned(n = 1, curr_arr = @exchange_values) ⇒ Object
- #print_owned_amounts(arr = @exchange_values) ⇒ Object
- #print_params ⇒ Object
- #print_prices(arr = @exchange_values) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ CepC
Returns a new instance of CepC.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cepc_coinbase.rb', line 7 def initialize(params={}) @curr_type = params.fetch(:currency_type, 'ETH') @daily_earn = params.fetch(:daily_earn, 0.0) @pay_limit = params.fetch(:pay_limit, 1.0) @pool_amount = params.fetch(:pool_amount, 0.0) @prices = params.fetch(:prices, {}) @exchange_values = params.fetch(:exchange_values, [['USD', '$']]) get_currencies rescue return -1 end |
Instance Attribute Details
#exchange_values=(value) ⇒ Object (writeonly)
Sets the attribute exchange_values
5 6 7 |
# File 'lib/cepc_coinbase.rb', line 5 def exchange_values=(value) @exchange_values = value end |
Instance Method Details
#amount_of(currency, amount, printable = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cepc_coinbase.rb', line 44 def amount_of(currency,amount,printable=false) price = price_of(currency) * amount return price unless printable printf "%s: %.2f %s\n", curr, price, curr_sym price rescue false end |
#exchange_diff(curr1, curr2, printable = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cepc_coinbase.rb', line 20 def exchange_diff(curr1,curr2,printable=false) diff = price_of(curr1) / price_of(curr2) return diff unless printable diff_str = "#{curr1} / #{curr2}" print_header 'CURRENCY(' + diff_str + ')' printf "%s currency: %.4f\n", diff_str, diff puts return diff rescue return -1 end |
#price_of(currency) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/cepc_coinbase.rb', line 35 def price_of(currency) price = @exchanges[currency.upcase] (price.nil?) ? raise : price.to_f rescue puts 'Currency does not exist!' # raise return -1 end |
#print_day_left ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cepc_coinbase.rb', line 112 def print_day_left print_header "Mining Estimation" if @daily_earn <= 0.0 puts "Your daily earn is #{@daily_earn}. You will never reached the limit!!!" return false end day_left = (@pay_limit - @pool_amount)/@daily_earn if day_left <= 0.0 printf "%d day left to payout! Please check your wallet.", absolute_day return true end absolute_day = day_left.ceil complete_perc = (@pool_amount / @pay_limit) * 100 if complete_perc <= 100.0 && complete_perc > 0.0 printf "%% %.2f completed!\n", complete_perc end printf "%d(%.2f) day left to payout!\n", absolute_day, day_left puts "Estimated day: #{Date.today+absolute_day}" puts return true rescue false end |
#print_exchange_amounts(arr = @exchange_values) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/cepc_coinbase.rb', line 56 def print_exchange_amounts(arr=@exchange_values) print_header " #{total_amount} #{@curr_type} EXCHANGE AMOUNTs" arr.each { |curr, curr_sym| amount_of(curr, curr_sym, true) } true rescue false end |
#print_n_day_earned(n = 1, curr_arr = @exchange_values) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/cepc_coinbase.rb', line 102 def print_n_day_earned(n = 1, curr_arr = @exchange_values) print_header "#{n} DAYs EARNING" curr_arr.each do |curr, curr_sym| print_n_day_earning(n, curr, curr_sym) end puts end |
#print_owned_amounts(arr = @exchange_values) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cepc_coinbase.rb', line 74 def print_owned_amounts(arr=@exchange_values) print_header "#{total_amount} #{@curr_type} DETAILED AMOUNTs" print_owned_exchange_amounts puts arr.each do |curr, curr_sym| print_owned_amount_of(curr, curr_sym) puts end true rescue false end |
#print_params ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/cepc_coinbase.rb', line 66 def print_params print_header "PARAMETERS" printf "%s: %f\n",'Daily Earn ', @daily_earn printf "%s: %f\n",'Pay Limit ', @pay_limit printf "%s: %f\n",'Pool Amount', @pool_amount puts end |
#print_prices(arr = @exchange_values) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cepc_coinbase.rb', line 90 def print_prices(arr=@exchange_values) print_header "1 #{@curr_type} PRICEs" arr.each do |curr, curr_sym| print_price(curr, curr_sym) end puts true rescue false end |