satoshi-unit 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/satoshi.rb +17 -3
- data/spec/satoshi_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57f6b19472e8e09b67722d760e8644bf491a39b
|
4
|
+
data.tar.gz: 50848d88f076cc33fd2e9f72112f5ee60ff92546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce606fb76a9db9060dbd10c4e5bdd712b825fc6beb033fdeb0d1c894dca2d366f8e831767980fbef20a3c919c95555ccc44c526d735279899ff9b2d359ddd6e
|
7
|
+
data.tar.gz: 5a1eb156e209a8272d8540e2cb54d4ab68f66cfaf0a8946375c5272c9d69bc6f488702ecd72013c9db6908a680ffe0d8e3835bd989110ea0433af0e2582673be
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/satoshi.rb
CHANGED
@@ -76,15 +76,29 @@ class Satoshi
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def +(i)
|
79
|
-
|
79
|
+
if i.kind_of?(Satoshi)
|
80
|
+
Satoshi.new(self.to_i + i, from_unit: :satoshi)
|
81
|
+
else
|
82
|
+
self.to_i + i
|
83
|
+
end
|
80
84
|
end
|
81
85
|
|
82
86
|
def -(i)
|
83
|
-
|
87
|
+
if i.kind_of?(Satoshi)
|
88
|
+
Satoshi.new(self.to_i - i, from_unit: :satoshi)
|
89
|
+
else
|
90
|
+
self.to_i - i
|
91
|
+
end
|
84
92
|
end
|
85
93
|
|
94
|
+
# IMPORTANT: multiplication is done on satoshis, not btc.
|
95
|
+
# 0.01*0.02 BTC will be a larger value.
|
86
96
|
def *(i)
|
87
|
-
|
97
|
+
if i.kind_of?(Satoshi)
|
98
|
+
Satoshi.new(self.to_i * i, from_unit: :satoshi)
|
99
|
+
else
|
100
|
+
self.to_i * i
|
101
|
+
end
|
88
102
|
end
|
89
103
|
|
90
104
|
def coerce(other)
|
data/spec/satoshi_spec.rb
CHANGED
@@ -76,4 +76,15 @@ describe Satoshi do
|
|
76
76
|
expect( -> { Satoshi.new(21_000_000) }).not_to raise_exception
|
77
77
|
end
|
78
78
|
|
79
|
+
it "returns satoshi for +,- and * methods if both operands are Satoshi" do
|
80
|
+
s1 = Satoshi.new(0.001, from_unit: :btc)
|
81
|
+
s2 = Satoshi.new(0.002, from_unit: :btc)
|
82
|
+
expect(s1+s2).to be_kind_of(Satoshi)
|
83
|
+
expect((s1+s2).to_unit).to eq(0.003)
|
84
|
+
expect(s2-s1).to be_kind_of(Satoshi)
|
85
|
+
expect((s2-s1).to_unit).to eq(0.001)
|
86
|
+
expect(s2*s1).to be_kind_of(Satoshi)
|
87
|
+
expect((s2*s1).to_unit).to eq(200)
|
88
|
+
end
|
89
|
+
|
79
90
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|