Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

satoshiproc-unit

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

satoshiproc-unit

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

SatoshiProc Unit

This tiny gem allows you to make easy conversions from one Proc denomination into another. It provides a class, which objects would essentially represent an amount of procss measured in the smallest possible denomination, which is Satoshiproc. You can then call methods on these objects to convert it various other denominations.

Installation

gem install satoshiproc-unit

Usage

Here's how it might look:

s = SatoshiProc.new(1) # By default, it accepts amounts in PROC denomination
s.to_i             # => 100000000 (in Satoshiprocs)
s.to_mbtc          # => 1000.0
s.to_btc           # => 1.0

When creating a SatoshiProc object, you can also specify which unit is being used to pass the amount, for example:

s = Satoshi.new(1, from_unit: :mproc)

s.to_i    # => 100000
s.to_mproc # => 1.0
s.to_proc  # => 0.001

There's also a special method which is called #to_unit, it always converts to the denomination specified in the :to_unit option in the constructor. It becomes really handy when you want to specify your preferred denomination used througout the program in just one place (to be able to change it later):

DENOMINATION = :mproc
s = SatoshiProc.new(1, from_unit: DENOMINATION, to_unit: DENOMINATION)
s.to_unit # => 1.0 (in mBTC)

This can be shortened to just the :unit option:

s = SatoshiProc.new(1, unit: DENOMINATION)

But, of course, if you want your "from" denomination and "to" denomination to be different, then you'd have to pass them both manually:

s = SatoshiProc.new(1, from_unit: :mproc, to_unit: :proc)
s.to_unit # => 0.001

###Comparing satoshiprocs

SatoshiProc objects come with methods and coercions for comparing itself with both other Satoshi objects and also numeric values:

s1 = SatoshiProc.new(1)
s2 = SatoshiProc.new(2)

s1 > s2  # => false
s1 < s2  # => true
s1 == s2 # => false

s1 > 1  # => true
1  > s2 # => false

Unit tests

Run rspec spec. Pull requests with more unit tests are welcome.

FAQs

Package last updated on 20 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc