latinum 0.5.3 → 0.5.4

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: 995a66ac306c3adf34324d0e1447dea9df94f16f
4
- data.tar.gz: 52277f8cc0847a25babc7ea0631075684c82e452
3
+ metadata.gz: ebfa6ade645c706ea5fc877d0a2cdc386c477e2f
4
+ data.tar.gz: e35cf37d0744a36bc805e5e8fba62c4e723e49b9
5
5
  SHA512:
6
- metadata.gz: 1ab641ec952d92003b562c8cb605e9957b7e06d8c650d351ed237ea61e2f60ee6be321da12ae12a290e7f0723b7ba5f44d300a2b2e0114fafbffb73e891bfb13
7
- data.tar.gz: 99b1af25e00450dc0ed9a2be09034bac442e25fa1af3b6b644371ffe30b3af14508fb1f05e6a127533bd507cc077c74ef533d42c78ecd2a8fdd3d54178a016dd
6
+ metadata.gz: 56f9fc756c232955e17a5c387c4a89ffede5c9a6a415315eab19645b41568583a859b006a40b30bd485efa403e430711e1dbdd5be2118ee61fa1da75d75d176d
7
+ data.tar.gz: a8764c151ca5831afd4e9ef72aa677f95547aca5d4d36bdb116a825ec3e4399c473e4148325d581ef68d3840f6842d78e17c4b45abfb8c6d56da6de29c3f1c6c
@@ -70,13 +70,16 @@ module Latinum
70
70
  groups = fix[remainder..-1].scan(/.{3}/).to_a
71
71
  groups.unshift(fix[0...remainder]) if remainder > 0
72
72
 
73
- whole = "#{sign}#{@symbol}#{groups.join(@delimeter)}"
74
- name = (@name && options[:format] == :full) ? " #{@name}" : ''
73
+ symbol = options.fetch(:symbol, @symbol)
74
+ value = "#{sign}#{symbol}#{groups.join(@delimeter)}"
75
+
76
+ name = options.fetch(:name, @name)
77
+ suffix = name ? " #{name}" : ''
75
78
 
76
79
  if @places > 0
77
- "#{whole}#{@separator}#{frac}#{name}"
80
+ "#{value}#{@separator}#{frac}#{suffix}"
78
81
  else
79
- "#{whole}#{name}"
82
+ "#{value}#{suffix}"
80
83
  end
81
84
  end
82
85
 
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'bigdecimal'
22
+ require 'bigdecimal/util'
22
23
 
23
24
  module Latinum
24
25
  # A fixed unit in a given named resource
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Latinum
22
- VERSION = "0.5.3"
22
+ VERSION = "0.5.4"
23
23
  end
data/lib/latinum.rb CHANGED
@@ -22,5 +22,3 @@ require 'latinum/bank'
22
22
  require 'latinum/resource'
23
23
  require 'latinum/collection'
24
24
 
25
- require 'bigdecimal'
26
- require 'bigdecimal/util'
@@ -35,8 +35,8 @@ module Latinum::BankSpec
35
35
  it "should format the amounts correctly" do
36
36
  resource = Latinum::Resource.new("10", "NZD")
37
37
 
38
- expect(@bank.format(resource, :format => :full)).to be == "$10.00 NZD"
39
- expect(@bank.format(resource, :format => :compact)).to be == "$10.00"
38
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
39
+ expect(@bank.format(resource, name: nil)).to be == "$10.00"
40
40
 
41
41
  resource = Latinum::Resource.new("391", "AUD")
42
42
  expect(@bank.format(resource)).to be == "$391.00 AUD"
@@ -51,7 +51,7 @@ module Latinum::BankSpec
51
51
  it "should round values when formatting" do
52
52
  resource = Latinum::Resource.new("19.9989", "NZD")
53
53
 
54
- expect(@bank.format(resource, :format => :full)).to be == "$20.00 NZD"
54
+ expect(@bank.format(resource)).to be == "$20.00 NZD"
55
55
  end
56
56
 
57
57
  it "should exchange currencies from NZD to AUD" do
@@ -0,0 +1,58 @@
1
+ # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'latinum/bank'
22
+ require 'latinum/currencies/global'
23
+ require 'latinum/formatters'
24
+
25
+ module Latinum::FormattersSpec
26
+ describe Latinum::Formatters::DecimalCurrencyFormatter do
27
+ before(:all) do
28
+ @bank = Latinum::Bank.new
29
+ @bank.import(Latinum::Currencies::Global)
30
+ end
31
+
32
+ let(:resource) {Latinum::Resource.load("10 NZD")}
33
+
34
+ it "should format output" do
35
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
36
+ end
37
+
38
+ it "should format output without name" do
39
+ expect(@bank.format(resource, name: nil)).to be == "$10.00"
40
+ end
41
+
42
+ it "should format output with alternative name" do
43
+ expect(@bank.format(resource, name: "Foo")).to be == "$10.00 Foo"
44
+ end
45
+
46
+ it "should format output" do
47
+ expect(@bank.format(resource)).to be == "$10.00 NZD"
48
+ end
49
+
50
+ it "should format output without symbol" do
51
+ expect(@bank.format(resource, symbol: nil)).to be == "10.00 NZD"
52
+ end
53
+
54
+ it "should format output with alternative symbol" do
55
+ expect(@bank.format(resource, symbol: "!!")).to be == "!!10.00 NZD"
56
+ end
57
+ end
58
+ end
@@ -22,11 +22,6 @@ require 'latinum/resource'
22
22
 
23
23
  module Latinum::ResourceSpec
24
24
  describe Latinum::Resource do
25
- before(:all) do
26
- @bank = Latinum::Bank.new
27
- @bank.import(Latinum::Currencies::Global)
28
- end
29
-
30
25
  it "should load and dump resources" do
31
26
  resource = Latinum::Resource.load("10 NZD")
32
27
  string_representation = Latinum::Resource.dump(resource)
@@ -41,6 +36,13 @@ module Latinum::ResourceSpec
41
36
  expect(Latinum::Resource.dump(nil)).to be nil
42
37
  end
43
38
 
39
+ it "should load and dump resources correctly" do
40
+ resource = Latinum::Resource.new(10, 'NZD')
41
+
42
+ expect(Latinum::Resource.load("10.0 NZD")).to be == resource
43
+ expect(Latinum::Resource.dump(resource)).to be == "10.0 NZD"
44
+ end
45
+
44
46
  it "should inspect nicely" do
45
47
  resource = Latinum::Resource.load("10 NZD")
46
48
 
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: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,7 @@ files:
73
73
  - lib/latinum/version.rb
74
74
  - spec/latinum/bank_spec.rb
75
75
  - spec/latinum/collection_spec.rb
76
+ - spec/latinum/formatters_spec.rb
76
77
  - spec/latinum/integrals_spec.rb
77
78
  - spec/latinum/resource_spec.rb
78
79
  homepage: ''
@@ -103,5 +104,6 @@ summary: Latinum is a simple gem for managing resource computations, including m
103
104
  test_files:
104
105
  - spec/latinum/bank_spec.rb
105
106
  - spec/latinum/collection_spec.rb
107
+ - spec/latinum/formatters_spec.rb
106
108
  - spec/latinum/integrals_spec.rb
107
109
  - spec/latinum/resource_spec.rb