satoshi-unit 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb777072c2a1a0ffce14e87ab258e5061cc66223
4
- data.tar.gz: 27105dfacc7adecf8652ef963e69fb33c2ac5c93
3
+ metadata.gz: b9a52a6380a911c6d3a292fc18bd198ca11d242b
4
+ data.tar.gz: 4e89d2299dee0d020841c19dad80ab23adfa75c7
5
5
  SHA512:
6
- metadata.gz: f5bc73d4e53c12217ef148520d65f483bd576ef628dec00ee3f27eefaf400b45891953d61b798d449e0e92ede229be15e4915419184ad0e5556ceba5821cd999
7
- data.tar.gz: a367d6b43c2a41047ab0fa66c30e23d9f6ff970cc192ddc50fe8d60d1bf6c302adab51a0017a792be438262e04720cb5682faaa9377caaa703843d993ba7afa9
6
+ metadata.gz: 5a13d36f81a9cb8c25b33288bb97b6d1ee59e5febf50f06cdc05bc827d3ab2207d8c124f980dccdfd46e01eba0d0af1025aca749352ec7b6b6619301294ccb55
7
+ data.tar.gz: cb2281253c87a3debdf361d12ff7fe9d84a5eab2f97cd9864a6c8051fabd73984a8cf0c0540705e77d03115da7fb0f0c140eb3053d2534c46c53dfe433a912eb
data/README.md CHANGED
@@ -33,7 +33,7 @@ specify your preferred denomination used througout the program in just one place
33
33
  (to be able to change it later):
34
34
 
35
35
  DENOMINATION = :mbtc
36
- s = Satoshi.new(1, from_unit: DENOMINATION, from_unit: DENOMINATION)
36
+ s = Satoshi.new(1, from_unit: DENOMINATION, to_unit: DENOMINATION)
37
37
  s.to_unit # => 1.0 (in mBTC)
38
38
 
39
39
  This can be shortened to just the `:unit` option:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -21,16 +21,16 @@ class Satoshi
21
21
  @value = convert_to_satoshi(n) if n
22
22
  end
23
23
 
24
- def to_btc
25
- to_denomination(UNIT_DENOMINATIONS[:btc])
24
+ def to_btc(as: :number)
25
+ to_denomination(UNIT_DENOMINATIONS[:btc], as: as)
26
26
  end
27
27
 
28
- def to_mbtc
29
- to_denomination(UNIT_DENOMINATIONS[:mbtc])
28
+ def to_mbtc(as: :number)
29
+ to_denomination(UNIT_DENOMINATIONS[:mbtc], as: as)
30
30
  end
31
31
 
32
- def to_unit
33
- to_denomination(UNIT_DENOMINATIONS[@to_unit])
32
+ def to_unit(as: :number)
33
+ to_denomination(UNIT_DENOMINATIONS[@to_unit], as: as)
34
34
  end
35
35
 
36
36
  def to_i
@@ -90,7 +90,7 @@ class Satoshi
90
90
 
91
91
  private
92
92
 
93
- def to_denomination(digits_after_delimiter)
93
+ def to_denomination(digits_after_delimiter, as: :number)
94
94
  sign = @value < 0 ? -1 : 1
95
95
  val = @value.abs
96
96
  return val if digits_after_delimiter <= 0
@@ -99,7 +99,13 @@ class Satoshi
99
99
  result.reverse!
100
100
  result = result.slice(0..digits_after_delimiter-1) + '.' + result.slice(digits_after_delimiter..17)
101
101
  result.reverse!
102
- result.sub(/\A0*/, '').sub(/0*\Z/, '').to_f*sign # remove zeros on both sides
102
+ result = result.sub(/\A0*/, '').sub(/0*\Z/, '') # remove zeros on both sides
103
+ if as == :number
104
+ result.to_f*sign
105
+ else
106
+ result = "0#{result}" if result =~ /\A\./
107
+ sign == -1 ? "-#{result}" : result
108
+ end
103
109
  end
104
110
 
105
111
  def convert_to_satoshi(n)
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: satoshi-unit 0.1.6 ruby lib
5
+ # stub: satoshi-unit 0.1.7 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "satoshi-unit"
9
- s.version = "0.1.6"
9
+ s.version = "0.1.7"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Roman Snitko"]
14
- s.date = "2014-07-29"
14
+ s.date = "2015-01-10"
15
15
  s.description = "Converts various bitcoin denominations in Satoshis and back"
16
16
  s.email = "roman.snitko@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -50,4 +50,10 @@ describe Satoshi do
50
50
  expect(s.to_unit).to eq(0)
51
51
  end
52
52
 
53
+ it "displays one Satoshi in human form, not math form" do
54
+ one_satoshi = Satoshi.new(1, from_unit: :satoshi, to_unit: :btc)
55
+ expect(one_satoshi.to_unit(as: :string)).not_to eq('1.0e-08')
56
+ expect(one_satoshi.to_unit(as: :string)).to eq('0.00000001')
57
+ end
58
+
53
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satoshi-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler