Class: Btc
- Inherits:
-
Object
- Object
- Btc
- Defined in:
- lib/btc.rb
Constant Summary collapse
- SATOSHI =
BigDecimal.new('0.00000001')
- MBTC =
BigDecimal.new('0.0001')
- BTC =
BigDecimal.new('1.0')
Class Method Summary collapse
- .from_mbtc(amt) ⇒ Object
- .from_satoshis(amt) ⇒ Object
- .valid_btc(amt) ⇒ Object
- .valid_mbtc(amt) ⇒ Object
- .valid_satoshis(amt) ⇒ Object
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(exp) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #==(other) ⇒ Object
- #btc ⇒ Object
-
#initialize(amt) ⇒ Btc
constructor
A new instance of Btc.
- #inspect ⇒ Object
- #mbtc ⇒ Object
- #satoshis ⇒ Object
Constructor Details
Class Method Details
.from_mbtc(amt) ⇒ Object
13 14 15 16 |
# File 'lib/btc.rb', line 13 def self.from_mbtc(amt) raise ArgumentError, 'mBTC amount must not be less than 0.00001' unless Btc.valid_mbtc(amt) Btc.new(BigDecimal.new(amt.to_f.to_s) * MBTC) end |
.from_satoshis(amt) ⇒ Object
18 19 20 21 |
# File 'lib/btc.rb', line 18 def self.from_satoshis(amt) raise ArgumentError, 'Satoshi amount must be > 1 or 0' unless Btc.valid_satoshis(amt) Btc.new(BigDecimal.new(amt.to_i.to_f.to_s) * SATOSHI) end |
.valid_btc(amt) ⇒ Object
31 32 33 |
# File 'lib/btc.rb', line 31 def self.valid_btc(amt) amt.to_f >= SATOSHI.to_f || amt.to_f == 0 end |
.valid_mbtc(amt) ⇒ Object
27 28 29 |
# File 'lib/btc.rb', line 27 def self.valid_mbtc(amt) amt.to_f >= MBTC.to_f || amt.to_f == 0 end |
.valid_satoshis(amt) ⇒ Object
23 24 25 |
# File 'lib/btc.rb', line 23 def self.valid_satoshis(amt) amt.to_i >= 0 end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 |
# File 'lib/btc.rb', line 67 def ==(other) @amt == other.btc end |
#btc ⇒ Object
35 36 37 |
# File 'lib/btc.rb', line 35 def btc @amt end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/btc.rb', line 71 def inspect "#<Btc BTC:#{btc} mBTC:#{mbtc} Satoshis:#{satoshis}>" end |
#mbtc ⇒ Object
39 40 41 |
# File 'lib/btc.rb', line 39 def mbtc @amt / MBTC end |
#satoshis ⇒ Object
43 44 45 |
# File 'lib/btc.rb', line 43 def satoshis @amt / SATOSHI end |