latinum 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/lib/latinum.rb +2 -0
- data/lib/latinum/bank.rb +7 -3
- data/lib/latinum/collection.rb +2 -0
- data/lib/latinum/currencies/global.rb +2 -0
- data/lib/latinum/formatters.rb +2 -1
- data/lib/latinum/resource.rb +2 -0
- data/lib/latinum/version.rb +3 -1
- data/spec/latinum/bank_spec.rb +10 -1
- data/spec/latinum/collection_spec.rb +2 -0
- data/spec/latinum/comparison_spec.rb +2 -0
- data/spec/latinum/formatters_spec.rb +2 -0
- data/spec/latinum/integrals_spec.rb +2 -0
- data/spec/latinum/resource_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8884a3ef10ea2656d2c0016be0a46808783d66f6b6245cfadf3df03e5352e452
|
4
|
+
data.tar.gz: 6ee07cd171635e5cc879b2dada4d52d2a0e31911090c125feb239093bc8850c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c38564220688bd0bb5e920bf3159bfedfef3d044e5d0073d0cbb294617c3fdb5f676f2da315a5e17363e10dc406775f156614bc18a3cbebaaa58ce899fe7b880
|
7
|
+
data.tar.gz: cd68db69fc29c633611f3b96c7af99b29fcf1283db4ad6a861712f713863de4d2339dec789b3e1551e51b069282fea3ea4ca8a6178918bddab7d1a9b953739ca
|
data/.travis.yml
CHANGED
@@ -4,7 +4,6 @@ cache: bundler
|
|
4
4
|
|
5
5
|
matrix:
|
6
6
|
include:
|
7
|
-
- rvm: 2.3
|
8
7
|
- rvm: 2.4
|
9
8
|
- rvm: 2.5
|
10
9
|
- rvm: 2.6
|
@@ -12,6 +11,7 @@ matrix:
|
|
12
11
|
os: osx
|
13
12
|
- rvm: 2.6
|
14
13
|
env: COVERAGE=BriefSummary,Coveralls
|
14
|
+
- rvm: 2.7
|
15
15
|
- rvm: truffleruby
|
16
16
|
- rvm: jruby-head
|
17
17
|
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -148,7 +148,7 @@ Formatting an amount is typically required for presentation to the end user:
|
|
148
148
|
> bank.format(nzd)
|
149
149
|
=> "$10.00 NZD"
|
150
150
|
|
151
|
-
> bank.format(aud, :
|
151
|
+
> bank.format(aud, name: nil)
|
152
152
|
=> "$5.00"
|
153
153
|
|
154
154
|
The bank can also be used to parse currency, which will depend on the priority of currencies if a symbol that matches multiple currencies is supplied:
|
data/Rakefile
CHANGED
data/lib/latinum.rb
CHANGED
data/lib/latinum/bank.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -102,13 +104,15 @@ module Latinum
|
|
102
104
|
parts = string.strip.split(/\s+/, 2)
|
103
105
|
|
104
106
|
if parts.size == 2
|
105
|
-
Resource.new(parts[0].gsub(/[
|
107
|
+
Resource.new(parts[0].gsub(/[^\-\.0-9]/, ''), parts[1])
|
106
108
|
else
|
107
109
|
# Lookup the named symbol, e.g. '$', and get the highest priority name:
|
108
|
-
symbol = @symbols.fetch(string.gsub(/[\-\.,0-9]/, ''), []).last
|
110
|
+
symbol = @symbols.fetch(string.gsub(/[\-\.,0-9]/, ''), []).last
|
109
111
|
|
110
112
|
if symbol
|
111
|
-
Resource.new(string.gsub(/[
|
113
|
+
Resource.new(string.gsub(/[^\-\.0-9]/, ''), symbol.last.to_s)
|
114
|
+
elsif default_name
|
115
|
+
Resource.new(string.gsub(/[^\-\.0-9]/, ''), default_name.to_s)
|
112
116
|
else
|
113
117
|
raise ArgumentError.new("Could not parse #{string}, could not determine currency!")
|
114
118
|
end
|
data/lib/latinum/collection.rb
CHANGED
data/lib/latinum/formatters.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -21,7 +23,6 @@
|
|
21
23
|
module Latinum
|
22
24
|
module Formatters
|
23
25
|
DEFAULT_OPTIONS = {
|
24
|
-
:format => :full
|
25
26
|
}
|
26
27
|
|
27
28
|
class PlainFormatter
|
data/lib/latinum/resource.rb
CHANGED
data/lib/latinum/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -19,5 +21,5 @@
|
|
19
21
|
# THE SOFTWARE.
|
20
22
|
|
21
23
|
module Latinum
|
22
|
-
VERSION = "1.
|
24
|
+
VERSION = "1.5.0"
|
23
25
|
end
|
data/spec/latinum/bank_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -69,12 +71,19 @@ RSpec.describe Latinum::Bank do
|
|
69
71
|
expect(aud).to be == Latinum::Resource.new("5", "AUD")
|
70
72
|
end
|
71
73
|
|
72
|
-
it "should
|
74
|
+
it "should parse strings into resources" do
|
73
75
|
expect(@bank.parse("$5")).to be == Latinum::Resource.new("5", "USD")
|
74
76
|
expect(@bank.parse("$5 NZD")).to be == Latinum::Resource.new("5", "NZD")
|
75
77
|
expect(@bank.parse("€5")).to be == Latinum::Resource.new("5", "EUR")
|
76
78
|
|
77
79
|
expect(@bank.parse("5 NZD")).to be == Latinum::Resource.new("5", "NZD")
|
80
|
+
|
81
|
+
expect(@bank.parse("-$5")).to be == Latinum::Resource.new("-5", "USD")
|
82
|
+
expect(@bank.parse("-$5 NZD")).to be == Latinum::Resource.new("-5", "NZD")
|
83
|
+
expect(@bank.parse("-€5")).to be == Latinum::Resource.new("-5", "EUR")
|
84
|
+
|
85
|
+
expect(@bank.parse("5", default_name: "EUR")).to be == Latinum::Resource.new("5", "EUR")
|
86
|
+
expect(@bank.parse("-5", default_name: "EUR")).to be == Latinum::Resource.new("-5", "EUR")
|
78
87
|
end
|
79
88
|
|
80
89
|
it "should fail to parse unknown resource" do
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 1.5.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:
|
11
|
+
date: 2020-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: covered
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.1.2
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Latinum is a simple gem for managing resource computations, including money
|