latinum 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e0f3fcf6c01e2d091b709e6a02aa8453871276d
4
- data.tar.gz: 65c8c8fed7bd38ee450212c631ea2fcccb9754e5
3
+ metadata.gz: d603254177726ef91a442d285c4ba917dd6cc003
4
+ data.tar.gz: bb81b377411b4ab43c8246c01c478740a0e4e8d4
5
5
  SHA512:
6
- metadata.gz: 92dbfdfa7064f905e6ae559a972c7d6bd42a9a516d3b9aef9cf953e9431de51074c6a9afb523c729a7fb3f024bd10d1c3ebec57a1c6d63cd3a85feb558f1f543
7
- data.tar.gz: 27fd684c753fa6ef97f0f12fdfa6d6ad3b42a5564ce15f089009a348b3061d6a5fc450b1629703b37ccbe3cca4d3f51333e53dcd23cf07dcacceea3ad94c21e3
6
+ metadata.gz: 0ae00f87d9c4a9b0a711b0736f2be1ec2e797fa4cdeb4ffc0dcedafe550b60e736e2d1ff665100f4a8665dea9bb34015458b7b55094aa8e2014033b1f3cc1705
7
+ data.tar.gz: 407e0b27c15a640b4893f70d413eb0eae70b5bcab2112c6e9af99590af9a2cda4de915740222bc332bc0653d73c1079b664a693f628fd4838643a9f9a11e0d15
data/README.md CHANGED
@@ -65,10 +65,9 @@ But, you can't add resources of different names together:
65
65
 
66
66
  To add multiple currencies together, use a collection:
67
67
 
68
- > currencies = Set.new
69
- > collection = Latinum::Collection.new(currencies)
68
+ > collection = Latinum::Collection.new
70
69
  > collection << [ten, twenty]
71
- > currencies.collect {|currency| collection[currency]}
70
+ > collection.collect(&:to_s)
72
71
  => [10.0 NZD, 20.0 AUD]
73
72
 
74
73
  #### Calculating Totals
@@ -57,6 +57,25 @@ module Latinum
57
57
  return self
58
58
  end
59
59
 
60
+ # Add something to this collection.
61
+ alias + <<
62
+
63
+ # Subtract something from this collection.
64
+ def - other
65
+ self << -other
66
+ end
67
+
68
+ # Allow negation of all values within the collection:
69
+ def -@
70
+ collection = self.class.new
71
+
72
+ @resources.each do |key, value|
73
+ collection.resources[key] = -value
74
+ end
75
+
76
+ return collection
77
+ end
78
+
60
79
  # Get a `Resource` for the given name:
61
80
  def [] key
62
81
  Resource.new(@resources[key], key)
@@ -64,7 +64,7 @@ module Latinum
64
64
  fix, frac = amount.abs.to_s('F').split(/\./, 2)
65
65
 
66
66
  # The sign of the number
67
- sign = amount.sign < 0 ? '-' : ''
67
+ sign = '-' if amount.negative?
68
68
 
69
69
  # Decimal places, e.g. the '.00' in '$10.00'
70
70
  frac = frac[0...@places].ljust(@places, @zero)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Latinum
22
- VERSION = "1.2.0"
22
+ VERSION = "1.3.0"
23
23
  end
@@ -21,65 +21,63 @@
21
21
  require 'latinum'
22
22
  require 'latinum/currencies/global'
23
23
 
24
- module Latinum::BankSpec
25
- describe Latinum::Bank do
26
- before(:all) do
27
- @bank = Latinum::Bank.new(Latinum::Currencies::Global)
28
-
29
- @bank << Latinum::ExchangeRate.new("NZD", "AUD", "0.5")
30
- end
24
+ RSpec.describe Latinum::Bank do
25
+ before(:all) do
26
+ @bank = Latinum::Bank.new(Latinum::Currencies::Global)
31
27
 
32
- it "should format the amounts correctly" do
33
- resource = Latinum::Resource.new("10", "NZD")
34
-
35
- expect(@bank.format(resource)).to be == "$10.00 NZD"
36
- expect(@bank.format(resource, name: nil)).to be == "$10.00"
37
-
38
- resource = Latinum::Resource.new("391", "AUD")
39
- expect(@bank.format(resource)).to be == "$391.00 AUD"
40
-
41
- resource = Latinum::Resource.new("-100", "NZD")
42
- expect(@bank.format(resource)).to be == "-$100.00 NZD"
43
-
44
- resource = Latinum::Resource.new("1.12345678", "BTC")
45
- expect(@bank.format(resource)).to be == "B⃦1.12345678 BTC"
46
- end
28
+ @bank << Latinum::ExchangeRate.new("NZD", "AUD", "0.5")
29
+ end
30
+
31
+ it "should format the amounts correctly" do
32
+ resource = Latinum::Resource.new("10", "NZD")
33
+
34
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
35
+ expect(@bank.format(resource, name: nil)).to be == "$10.00"
36
+
37
+ resource = Latinum::Resource.new("391", "AUD")
38
+ expect(@bank.format(resource)).to be == "$391.00 AUD"
47
39
 
48
- it "should round up using correct precision" do
49
- resource = Latinum::Resource.new("19.9989", "NZD")
50
-
51
- expect(@bank.round(resource)).to be == Latinum::Resource.new(20, "NZD")
52
- end
40
+ resource = Latinum::Resource.new("-100", "NZD")
41
+ expect(@bank.format(resource)).to be == "-$100.00 NZD"
42
+
43
+ resource = Latinum::Resource.new("1.12345678", "BTC")
44
+ expect(@bank.format(resource)).to be == "B⃦1.12345678 BTC"
45
+ end
46
+
47
+ it "should round up using correct precision" do
48
+ resource = Latinum::Resource.new("19.9989", "NZD")
53
49
 
54
- it "should round down using correct precision" do
55
- resource = Latinum::Resource.new("19.991", "NZD")
56
-
57
- expect(@bank.round(resource)).to be == Latinum::Resource.new("19.99", "NZD")
58
- end
50
+ expect(@bank.round(resource)).to be == Latinum::Resource.new(20, "NZD")
51
+ end
52
+
53
+ it "should round down using correct precision" do
54
+ resource = Latinum::Resource.new("19.991", "NZD")
59
55
 
60
- it "should round values when formatting" do
61
- resource = Latinum::Resource.new("19.9989", "NZD")
62
-
63
- expect(@bank.format(resource)).to be == "$20.00 NZD"
64
- end
56
+ expect(@bank.round(resource)).to be == Latinum::Resource.new("19.99", "NZD")
57
+ end
58
+
59
+ it "should round values when formatting" do
60
+ resource = Latinum::Resource.new("19.9989", "NZD")
65
61
 
66
- it "should exchange currencies from NZD to AUD" do
67
- nzd = Latinum::Resource.new("10", "NZD")
68
-
69
- aud = @bank.exchange nzd, "AUD"
70
- expect(aud).to be == Latinum::Resource.new("5", "AUD")
71
- end
62
+ expect(@bank.format(resource)).to be == "$20.00 NZD"
63
+ end
64
+
65
+ it "should exchange currencies from NZD to AUD" do
66
+ nzd = Latinum::Resource.new("10", "NZD")
72
67
 
73
- it "should parser strings into resources" do
74
- expect(@bank.parse("$5")).to be == Latinum::Resource.new("5", "USD")
75
- expect(@bank.parse("$5 NZD")).to be == Latinum::Resource.new("5", "NZD")
76
- expect(@bank.parse("€5")).to be == Latinum::Resource.new("5", "EUR")
77
-
78
- expect(@bank.parse("5 NZD")).to be == Latinum::Resource.new("5", "NZD")
79
- end
68
+ aud = @bank.exchange nzd, "AUD"
69
+ expect(aud).to be == Latinum::Resource.new("5", "AUD")
70
+ end
71
+
72
+ it "should parser strings into resources" do
73
+ expect(@bank.parse("$5")).to be == Latinum::Resource.new("5", "USD")
74
+ expect(@bank.parse("$5 NZD")).to be == Latinum::Resource.new("5", "NZD")
75
+ expect(@bank.parse("€5")).to be == Latinum::Resource.new("5", "EUR")
80
76
 
81
- it "should fail to parse unknown resource" do
82
- expect{@bank.parse("B5")}.to raise_error(ArgumentError)
83
- end
77
+ expect(@bank.parse("5 NZD")).to be == Latinum::Resource.new("5", "NZD")
78
+ end
79
+
80
+ it "should fail to parse unknown resource" do
81
+ expect{@bank.parse("B5")}.to raise_error(ArgumentError)
84
82
  end
85
83
  end
@@ -23,76 +23,82 @@ require 'latinum/currencies/global'
23
23
 
24
24
  require 'set'
25
25
 
26
- module Latinum::CollectionSpec
27
- describe Latinum::Collection do
28
- it "can set an initial value" do
29
- subject["NZD"] = BigDecimal.new("20")
30
-
31
- expect(subject["NZD"]).to be == Latinum::Resource.load("20 NZD")
32
- end
26
+ RSpec.describe Latinum::Collection do
27
+ it "can set an initial value" do
28
+ subject["NZD"] = BigDecimal.new("20")
33
29
 
34
- it "should sum up currencies correctly" do
35
- resource = Latinum::Resource.new("10", "NZD")
36
-
37
- subject << resource
38
- expect(subject["NZD"]).to be == resource
39
-
40
- subject << resource
41
- expect(subject["NZD"]).to be == (resource * 2)
42
- end
30
+ expect(subject["NZD"]).to be == Latinum::Resource.load("20 NZD")
31
+ end
32
+
33
+ it "can be negated" do
34
+ subject["NZD"] = BigDecimal.new("20")
35
+
36
+ negated = -subject
37
+
38
+ expect(negated["NZD"]).to be == BigDecimal.new("-20")
39
+ end
40
+
41
+ it "should sum up currencies correctly" do
42
+ resource = Latinum::Resource.new("10", "NZD")
43
+
44
+ subject << resource
45
+ expect(subject["NZD"]).to be == resource
46
+
47
+ subject << resource
48
+ expect(subject["NZD"]).to be == (resource * 2)
49
+ end
50
+
51
+ it "should sum up multiple currencies correctly" do
52
+ resources = [
53
+ Latinum::Resource.new("10", "NZD"),
54
+ Latinum::Resource.new("10", "AUD"),
55
+ Latinum::Resource.new("10", "USD"),
56
+ Latinum::Resource.new("10", "NZD"),
57
+ Latinum::Resource.new("10", "AUD"),
58
+ Latinum::Resource.new("10", "USD"),
59
+ ]
43
60
 
44
- it "should sum up multiple currencies correctly" do
45
- resources = [
46
- Latinum::Resource.new("10", "NZD"),
47
- Latinum::Resource.new("10", "AUD"),
48
- Latinum::Resource.new("10", "USD"),
49
- Latinum::Resource.new("10", "NZD"),
50
- Latinum::Resource.new("10", "AUD"),
51
- Latinum::Resource.new("10", "USD"),
52
- ]
53
-
54
- subject = Latinum::Collection.new
55
- subject << resources
56
-
57
- expect(subject["NZD"]).to be == (resources[0] * 2)
58
- expect(subject.names).to be == Set.new(["NZD", "AUD", "USD"])
59
- end
61
+ subject = Latinum::Collection.new
62
+ subject << resources
63
+
64
+ expect(subject["NZD"]).to be == (resources[0] * 2)
65
+ expect(subject.names).to be == Set.new(["NZD", "AUD", "USD"])
66
+ end
67
+
68
+ it "can add two collections together" do
69
+ other_resources = [
70
+ Latinum::Resource.new("10", "NZD"),
71
+ Latinum::Resource.new("10", "AUD"),
72
+ Latinum::Resource.new("10", "USD"),
73
+ ]
74
+
75
+ other_collection = Latinum::Collection.new
76
+ other_collection << other_resources
77
+
78
+ resources = [
79
+ Latinum::Resource.new("10", "NZD"),
80
+ Latinum::Resource.new("10", "AUD"),
81
+ Latinum::Resource.new("10", "USD"),
82
+ ]
83
+
84
+ subject << resources
85
+ subject << other_collection
86
+
87
+ expect(subject["NZD"]).to be == Latinum::Resource.load("20 NZD")
88
+ expect(subject["AUD"]).to be == Latinum::Resource.load("20 AUD")
89
+ expect(subject["USD"]).to be == Latinum::Resource.load("20 USD")
90
+ end
91
+
92
+ it "can enumerate resources" do
93
+ resources = [
94
+ Latinum::Resource.new("10", "NZD"),
95
+ Latinum::Resource.new("10", "AUD"),
96
+ Latinum::Resource.new("10", "USD"),
97
+ ]
60
98
 
61
- it "can add two collections together" do
62
- other_resources = [
63
- Latinum::Resource.new("10", "NZD"),
64
- Latinum::Resource.new("10", "AUD"),
65
- Latinum::Resource.new("10", "USD"),
66
- ]
67
-
68
- other_collection = Latinum::Collection.new
69
- other_collection << other_resources
70
-
71
- resources = [
72
- Latinum::Resource.new("10", "NZD"),
73
- Latinum::Resource.new("10", "AUD"),
74
- Latinum::Resource.new("10", "USD"),
75
- ]
76
-
77
- subject << resources
78
- subject << other_collection
79
-
80
- expect(subject["NZD"]).to be == Latinum::Resource.load("20 NZD")
81
- expect(subject["AUD"]).to be == Latinum::Resource.load("20 AUD")
82
- expect(subject["USD"]).to be == Latinum::Resource.load("20 USD")
83
- end
99
+ collection = Latinum::Collection.new
100
+ collection << resources
84
101
 
85
- it "can enumerate resources" do
86
- resources = [
87
- Latinum::Resource.new("10", "NZD"),
88
- Latinum::Resource.new("10", "AUD"),
89
- Latinum::Resource.new("10", "USD"),
90
- ]
91
-
92
- collection = Latinum::Collection.new
93
- collection << resources
94
-
95
- expect(collection.each.to_a).to be == resources
96
- end
102
+ expect(collection.each.to_a).to be == resources
97
103
  end
98
104
  end
@@ -20,23 +20,21 @@
20
20
 
21
21
  require 'latinum/resource'
22
22
 
23
- module Latinum::ComparisonSpec
24
- describe Latinum::Resource do
25
- it "should be comparable to numeric values" do
26
- resource = Latinum::Resource.load("10 NZD")
27
-
28
- expect(resource).to be < 20
29
- expect(resource).to be > 5
30
- expect(resource).to be == 10
31
- end
23
+ RSpec.describe Latinum::Resource do
24
+ it "should be comparable to numeric values" do
25
+ resource = Latinum::Resource.load("10 NZD")
32
26
 
33
- it "should compare with nil" do
34
- a = Latinum::Resource.load("10 NZD")
35
-
36
- expect{a <=> nil}.to_not raise_exception
37
- expect{a == nil}.to_not raise_exception
38
- expect(a <=> nil).to be == nil
39
- expect(a == nil).to be == false
40
- end
27
+ expect(resource).to be < 20
28
+ expect(resource).to be > 5
29
+ expect(resource).to be == 10
30
+ end
31
+
32
+ it "should compare with nil" do
33
+ a = Latinum::Resource.load("10 NZD")
34
+
35
+ expect{a <=> nil}.to_not raise_exception
36
+ expect{a == nil}.to_not raise_exception
37
+ expect(a <=> nil).to be == nil
38
+ expect(a == nil).to be == false
41
39
  end
42
40
  end
@@ -22,66 +22,72 @@ require 'latinum/bank'
22
22
  require 'latinum/currencies/global'
23
23
  require 'latinum/formatters'
24
24
 
25
- module Latinum::FormattersSpec
26
- describe Latinum::Formatters::PlainFormatter.new(name: "NZD") do
27
- let(:amount) {BigDecimal.new(10)}
28
-
29
- it "can convert to integral" do
30
- expect(subject.to_integral(amount)).to be == 10
31
- end
32
-
33
- it "can convert from integral" do
34
- expect(subject.from_integral(10)).to be == amount
35
- end
36
-
37
- it "can do basic formatting" do
38
- expect(subject.format(amount)).to be == "10.0 NZD"
39
- end
25
+ RSpec.describe Latinum::Formatters::PlainFormatter.new(name: "NZD") do
26
+ let(:amount) {BigDecimal.new(10)}
27
+
28
+ it "can convert to integral" do
29
+ expect(subject.to_integral(amount)).to be == 10
40
30
  end
41
31
 
42
- describe Latinum::Formatters::DecimalCurrencyFormatter do
43
- before(:all) do
44
- @bank = Latinum::Bank.new
45
- @bank.import(Latinum::Currencies::Global)
46
- end
47
-
48
- let(:resource) {Latinum::Resource.load("10 NZD")}
49
-
50
- it "should format output" do
51
- expect(@bank.format(resource)).to be == "$10.00 NZD"
52
- end
53
-
54
- it "should format output without name" do
55
- expect(@bank.format(resource, name: nil)).to be == "$10.00"
56
- end
57
-
58
- it "should format output with alternative name" do
59
- expect(@bank.format(resource, name: "Foo")).to be == "$10.00 Foo"
60
- end
61
-
62
- it "should format output" do
63
- expect(@bank.format(resource)).to be == "$10.00 NZD"
64
- end
65
-
66
- it "should format output without symbol" do
67
- expect(@bank.format(resource, symbol: nil)).to be == "10.00 NZD"
68
- end
69
-
70
- it "should format output with alternative symbol" do
71
- expect(@bank.format(resource, symbol: "!!")).to be == "!!10.00 NZD"
72
- end
32
+ it "can convert from integral" do
33
+ expect(subject.from_integral(10)).to be == amount
73
34
  end
74
35
 
75
- describe Latinum::Formatters::DecimalCurrencyFormatter do
76
- before(:all) do
77
- @bank = Latinum::Bank.new
78
- @bank.import(Latinum::Currencies::Global)
79
- end
80
-
81
- let(:resource) {Latinum::Resource.load("10 JPY")}
36
+ it "can do basic formatting" do
37
+ expect(subject.format(amount)).to be == "10.0 NZD"
38
+ end
39
+ end
40
+
41
+ RSpec.describe Latinum::Formatters::DecimalCurrencyFormatter do
42
+ before(:all) do
43
+ @bank = Latinum::Bank.new
44
+ @bank.import(Latinum::Currencies::Global)
45
+ end
46
+
47
+ let(:resource) {Latinum::Resource.load("10 NZD")}
48
+
49
+ it "should format output" do
50
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
51
+ end
52
+
53
+ it "should format output without name" do
54
+ expect(@bank.format(resource, name: nil)).to be == "$10.00"
55
+ end
56
+
57
+ it "should format output with alternative name" do
58
+ expect(@bank.format(resource, name: "Foo")).to be == "$10.00 Foo"
59
+ end
60
+
61
+ it "should format output" do
62
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
63
+ end
64
+
65
+ it "should format output without symbol" do
66
+ expect(@bank.format(resource, symbol: nil)).to be == "10.00 NZD"
67
+ end
68
+
69
+ it "should format output with alternative symbol" do
70
+ expect(@bank.format(resource, symbol: "!!")).to be == "!!10.00 NZD"
71
+ end
72
+
73
+ context "negative zero" do
74
+ let(:resource) {Latinum::Resource.new(BigDecimal.new("-0"), "NZD")}
82
75
 
83
- it "should format without separator or fractional part" do
84
- expect(@bank.format(resource)).to be == "¥10 JPY"
76
+ it "should format as (positve) zero" do
77
+ expect(@bank.format(resource)).to be == "$0.00 NZD"
85
78
  end
86
79
  end
87
80
  end
81
+
82
+ RSpec.describe Latinum::Formatters::DecimalCurrencyFormatter do
83
+ before(:all) do
84
+ @bank = Latinum::Bank.new
85
+ @bank.import(Latinum::Currencies::Global)
86
+ end
87
+
88
+ let(:resource) {Latinum::Resource.load("10 JPY")}
89
+
90
+ it "should format without separator or fractional part" do
91
+ expect(@bank.format(resource)).to be == "¥10 JPY"
92
+ end
93
+ end
@@ -21,27 +21,25 @@
21
21
  require 'latinum'
22
22
  require 'latinum/currencies/global'
23
23
 
24
- module Latinum::CollectionSpec
25
- describe Latinum::Bank do
26
- before(:all) do
27
- @bank = Latinum::Bank.new
28
- @bank.import(Latinum::Currencies::Global)
29
- end
24
+ RSpec.describe Latinum::Bank do
25
+ before(:all) do
26
+ @bank = Latinum::Bank.new
27
+ @bank.import(Latinum::Currencies::Global)
28
+ end
29
+
30
+ it "should convert to NZD integral value" do
31
+ resource = Latinum::Resource.new("10", "NZD")
32
+
33
+ expect(@bank.to_integral(resource)).to be == 1000
34
+
35
+ expect(@bank.from_integral(1000, "NZD")).to be == resource
36
+ end
37
+
38
+ it "should convert to BTC integral value" do
39
+ resource = Latinum::Resource.new("1.12345678", "BTC")
30
40
 
31
- it "should convert to NZD integral value" do
32
- resource = Latinum::Resource.new("10", "NZD")
33
-
34
- expect(@bank.to_integral(resource)).to be == 1000
35
-
36
- expect(@bank.from_integral(1000, "NZD")).to be == resource
37
- end
41
+ expect(@bank.to_integral(resource)).to be == 112345678
38
42
 
39
- it "should convert to BTC integral value" do
40
- resource = Latinum::Resource.new("1.12345678", "BTC")
41
-
42
- expect(@bank.to_integral(resource)).to be == 112345678
43
-
44
- expect(@bank.from_integral(112345678, "BTC")).to be == resource
45
- end
43
+ expect(@bank.from_integral(112345678, "BTC")).to be == resource
46
44
  end
47
45
  end
@@ -20,113 +20,111 @@
20
20
 
21
21
  require 'latinum/resource'
22
22
 
23
- module Latinum::ResourceSpec
24
- describe Latinum::Resource do
25
- it "should load and dump resources" do
26
- resource = Latinum::Resource.load("10 NZD")
27
- string_representation = Latinum::Resource.dump(resource)
28
-
29
- loaded_resource = Latinum::Resource.load(string_representation)
30
-
31
- expect(loaded_resource).to be == loaded_resource
32
- end
23
+ RSpec.describe Latinum::Resource do
24
+ it "should load and dump resources" do
25
+ resource = Latinum::Resource.load("10 NZD")
26
+ string_representation = Latinum::Resource.dump(resource)
33
27
 
34
- it "should load and dump nil correctly" do
35
- expect(Latinum::Resource.load(nil)).to be nil
36
- expect(Latinum::Resource.dump(nil)).to be nil
37
- end
28
+ loaded_resource = Latinum::Resource.load(string_representation)
38
29
 
39
- it "should handle empty strings correctly" do
40
- expect(Latinum::Resource.load("")).to be nil
41
- end
30
+ expect(loaded_resource).to be == loaded_resource
31
+ end
32
+
33
+ it "should load and dump nil correctly" do
34
+ expect(Latinum::Resource.load(nil)).to be nil
35
+ expect(Latinum::Resource.dump(nil)).to be nil
36
+ end
37
+
38
+ it "should handle empty strings correctly" do
39
+ expect(Latinum::Resource.load("")).to be nil
40
+ end
41
+
42
+ it "should handle whitespace strings correctly" do
43
+ expect(Latinum::Resource.load(" ")).to be nil
44
+ end
45
+
46
+ it "should load and dump resources correctly" do
47
+ resource = Latinum::Resource.new(10, 'NZD')
42
48
 
43
- it "should handle whitespace strings correctly" do
44
- expect(Latinum::Resource.load(" ")).to be nil
45
- end
49
+ expect(Latinum::Resource.load("10.0 NZD")).to be == resource
50
+ expect(Latinum::Resource.dump(resource)).to be == "10.0 NZD"
51
+ end
52
+
53
+ it "should inspect nicely" do
54
+ resource = Latinum::Resource.load("10 NZD")
46
55
 
47
- it "should load and dump resources correctly" do
48
- resource = Latinum::Resource.new(10, 'NZD')
49
-
50
- expect(Latinum::Resource.load("10.0 NZD")).to be == resource
51
- expect(Latinum::Resource.dump(resource)).to be == "10.0 NZD"
52
- end
56
+ expect(resource.inspect).to be == '#<Latinum::Resource "10.0 NZD">'
57
+ end
58
+
59
+ it "should compute percentage difference" do
60
+ original_price = Latinum::Resource.load("10 NZD")
61
+ discount_price = Latinum::Resource.load("5 NZD")
53
62
 
54
- it "should inspect nicely" do
55
- resource = Latinum::Resource.load("10 NZD")
56
-
57
- expect(resource.inspect).to be == '#<Latinum::Resource "10.0 NZD">'
58
- end
63
+ discount = (original_price - discount_price) / original_price
59
64
 
60
- it "should compute percentage difference" do
61
- original_price = Latinum::Resource.load("10 NZD")
62
- discount_price = Latinum::Resource.load("5 NZD")
63
-
64
- discount = (original_price - discount_price) / original_price
65
-
66
- expect(discount).to be == 0.5
67
- end
65
+ expect(discount).to be == 0.5
66
+ end
67
+
68
+ it "should not divide" do
69
+ original_price = Latinum::Resource.load("10 NZD")
70
+ discount_price = Latinum::Resource.load("5 USD")
68
71
 
69
- it "should not divide" do
70
- original_price = Latinum::Resource.load("10 NZD")
71
- discount_price = Latinum::Resource.load("5 USD")
72
-
73
- expect{original_price / discount_price}.to raise_exception(Latinum::DifferentResourceNameError)
74
- end
72
+ expect{original_price / discount_price}.to raise_exception(Latinum::DifferentResourceNameError)
73
+ end
74
+
75
+ it "should compute quotient" do
76
+ original_price = Latinum::Resource.load("10 NZD")
75
77
 
76
- it "should compute quotient" do
77
- original_price = Latinum::Resource.load("10 NZD")
78
-
79
- expect(original_price / 2.0).to be == Latinum::Resource.load("5 NZD")
80
- end
78
+ expect(original_price / 2.0).to be == Latinum::Resource.load("5 NZD")
79
+ end
80
+
81
+ it "should add two resources of the same symbol" do
82
+ a = Latinum::Resource.load("10 NZD")
83
+ b = Latinum::Resource.load("5 NZD")
84
+ c = Latinum::Resource.load("15 NZD")
81
85
 
82
- it "should add two resources of the same symbol" do
83
- a = Latinum::Resource.load("10 NZD")
84
- b = Latinum::Resource.load("5 NZD")
85
- c = Latinum::Resource.load("15 NZD")
86
-
87
- expect(a+b).to be == c
88
- end
86
+ expect(a+b).to be == c
87
+ end
88
+
89
+ it "should fail two resources of different symbol" do
90
+ a = Latinum::Resource.load("10 NZD")
91
+ b = Latinum::Resource.load("5 USD")
89
92
 
90
- it "should fail two resources of different symbol" do
91
- a = Latinum::Resource.load("10 NZD")
92
- b = Latinum::Resource.load("5 USD")
93
-
94
- expect{a+b}.to raise_error(Latinum::DifferentResourceNameError)
95
- end
93
+ expect{a+b}.to raise_error(Latinum::DifferentResourceNameError)
94
+ end
95
+
96
+ it "should be able to negate a value" do
97
+ a = Latinum::Resource.load("10 NZD")
98
+ b = Latinum::Resource.load("-10 NZD")
96
99
 
97
- it "should be able to negate a value" do
98
- a = Latinum::Resource.load("10 NZD")
99
- b = Latinum::Resource.load("-10 NZD")
100
-
101
- expect(-a).to be == b
102
- end
100
+ expect(-a).to be == b
101
+ end
102
+
103
+ it "can be used as a hash key" do
104
+ a = Latinum::Resource.load("10 NZD")
105
+ b = Latinum::Resource.load("0 NZD")
103
106
 
104
- it "can be used as a hash key" do
105
- a = Latinum::Resource.load("10 NZD")
106
- b = Latinum::Resource.load("0 NZD")
107
-
108
- hash = {a => true}
109
-
110
- expect(hash).to be_include a
111
- expect(hash).to_not be_include b
112
- end
107
+ hash = {a => true}
113
108
 
114
- it "can be zero" do
115
- a = Latinum::Resource.load("10 NZD")
116
- b = Latinum::Resource.load("0 NZD")
117
-
118
- expect(a).to_not be_zero
119
- expect(b).to be_zero
120
- end
109
+ expect(hash).to be_include a
110
+ expect(hash).to_not be_include b
111
+ end
112
+
113
+ it "can be zero" do
114
+ a = Latinum::Resource.load("10 NZD")
115
+ b = Latinum::Resource.load("0 NZD")
116
+
117
+ expect(a).to_not be_zero
118
+ expect(b).to be_zero
119
+ end
120
+
121
+ it "can be eql?" do
122
+ a = Latinum::Resource.load("10 NZD")
123
+ b = Latinum::Resource.load("0 NZD")
124
+ c = Latinum::Resource.load("0 NZD")
121
125
 
122
- it "can be eql?" do
123
- a = Latinum::Resource.load("10 NZD")
124
- b = Latinum::Resource.load("0 NZD")
125
- c = Latinum::Resource.load("0 NZD")
126
-
127
- expect(a).to be_eql a
128
- expect(a).to_not be_eql b
129
- expect(b).to be_eql c
130
- end
126
+ expect(a).to be_eql a
127
+ expect(a).to_not be_eql b
128
+ expect(b).to be_eql c
131
129
  end
132
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
- rubygems_version: 2.6.10
102
+ rubygems_version: 2.6.12
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Latinum is a simple gem for managing resource computations, including money