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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/satoshi.rb +17 -3
  4. data/spec/satoshi_spec.rb +11 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e33e2b8e9fff83147605f66272e31bfa2df9bfd8
4
- data.tar.gz: 339fe64084bf5733e5ef19f67c1f9d4d949af564
3
+ metadata.gz: c57f6b19472e8e09b67722d760e8644bf491a39b
4
+ data.tar.gz: 50848d88f076cc33fd2e9f72112f5ee60ff92546
5
5
  SHA512:
6
- metadata.gz: 41a899656d58c46fcbe7f619a3db8222bab29faa58629c1a583998d91fd48fbf7364c5f837cf1601d42db35ef63cbe5bf6e3403fddd54c48cec6f52fe1e46c66
7
- data.tar.gz: 13250853c7bc52ba439c5b397dab7ef6600a01094dbd46131b8bc962fea15d8f5a12249849e73e9ff58120b9e4258a6ab9aadd84d1a6b097558b02df519113e0
6
+ metadata.gz: 0ce606fb76a9db9060dbd10c4e5bdd712b825fc6beb033fdeb0d1c894dca2d366f8e831767980fbef20a3c919c95555ccc44c526d735279899ff9b2d359ddd6e
7
+ data.tar.gz: 5a1eb156e209a8272d8540e2cb54d4ab68f66cfaf0a8946375c5272c9d69bc6f488702ecd72013c9db6908a680ffe0d8e3835bd989110ea0433af0e2582673be
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -76,15 +76,29 @@ class Satoshi
76
76
  end
77
77
 
78
78
  def +(i)
79
- self.to_i + i
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
- self.to_i - i
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
- self.to_i * i
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)
@@ -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.1
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-07 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler