Bitcoin Money!
The Money gem is a popular gem for Ruby. Ruby needs a gem like Money, for Bitcoin!
But BTC is unique, so this simple object should be unique.
Installation
Add this line to your application's Gemfile:
gem 'bitcoin-money'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bitcoin-money
Usage
Require it!
require 'btc'
Create from whichever unit of BTC.
a = BTC.new(0.012)
b = BTC.from_mbtc(12)
c = BTC.from_satoshis(120000)
a == b # true
b == c # true
# a == b == c
Get value in any unit of BTC.
b # => #<Btc BTC:0.012 mBTC: 12.0 Satoshis: 120000.0>
b.mbtc # => BigDecimal.new('12.0')
b.satoshis # => BigDecimal.new('120000.0')
b.btc # => BigDecimal.new('0.012')
Perform operations.
a + b # == BTC.new(0.024)
a * a # == BTC.new(0.000144)
a / c # == BTC.new(1)
# also ** and -
Contributing
- Fork it ( https://github.com/zenchilabs/bitcoin-money/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request