formatting 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/formatting.gemspec +1 -0
- data/lib/formatting/currency.rb +11 -3
- data/lib/formatting/number.rb +12 -0
- data/lib/formatting/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa1abfad65855a703931fa20362f151000298872
|
4
|
+
data.tar.gz: 344114e77b5029eb1a39664743923c2d24f9860b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45a173c7ead2b95c59d8cafdbb154e3e54d615f8d6148a67ac7fb19fd40c9fe02bd38948f454b37d74375482662d9050e0b8a0f574e2a7f4bef5ec7db68ea29
|
7
|
+
data.tar.gz: 3aa14ccd4b6fd33fd18fd8da8638409de22673dfb3ef2dbe5d6a783c7c7f18f641acc3049eeb05a5befe33f46704ea7979bce664532f954448ba47ed5ca96828
|
data/formatting.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_dependency "attr_extras"
|
20
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
22
|
spec.add_development_dependency "rake"
|
22
23
|
spec.add_development_dependency "rspec"
|
data/lib/formatting/currency.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
require "attr_extras"
|
2
|
+
|
1
3
|
module Formatting
|
2
4
|
module Currency
|
3
|
-
include Number
|
4
|
-
|
5
5
|
def format_currency(record_or_currency, amount_or_method, opts = {})
|
6
|
+
FormatCurrency.new(record_or_currency, amount_or_method, opts).format
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class FormatCurrency
|
11
|
+
pattr_initialize :record_or_currency, :amount_or_method, :opts
|
12
|
+
|
13
|
+
def format
|
6
14
|
format_string = opts.fetch(:format, "<amount> <currency>")
|
7
15
|
skip_currency = opts.fetch(:skip_currency, false)
|
8
16
|
|
@@ -26,7 +34,7 @@ module Formatting
|
|
26
34
|
|
27
35
|
return "" if amount.nil?
|
28
36
|
|
29
|
-
amount =
|
37
|
+
amount = FormatNumber.new(amount, opts).format
|
30
38
|
apply_format_string(format_string, amount, currency)
|
31
39
|
end
|
32
40
|
|
data/lib/formatting/number.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
+
require "attr_extras"
|
2
|
+
|
1
3
|
module Formatting
|
2
4
|
module Number
|
3
5
|
def format_number(number, opts = {})
|
6
|
+
FormatNumber.new(number, opts).format
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class FormatNumber
|
11
|
+
pattr_initialize :input_number, :opts
|
12
|
+
|
13
|
+
def format
|
4
14
|
thousands_separator = opts.fetch(:thousands_separator) { default_thousands_separator }
|
5
15
|
decimal_separator = opts.fetch(:decimal_separator) { default_decimal_separator }
|
6
16
|
round = opts.fetch(:round, 2)
|
@@ -8,6 +18,8 @@ module Formatting
|
|
8
18
|
explicit_sign = opts.fetch(:explicit_sign, false)
|
9
19
|
blank_when_zero = opts.fetch(:blank_when_zero, false)
|
10
20
|
|
21
|
+
number = input_number
|
22
|
+
|
11
23
|
has_decimals = number.to_s.include?(".")
|
12
24
|
|
13
25
|
if blank_when_zero
|
data/lib/formatting/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: attr_extras
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|