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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8491d72d7e09b9a42a8c97708417a144262245a4
4
- data.tar.gz: 9a2be257d8fef3a05d78945223bde008c89ca9b4
3
+ metadata.gz: aa1abfad65855a703931fa20362f151000298872
4
+ data.tar.gz: 344114e77b5029eb1a39664743923c2d24f9860b
5
5
  SHA512:
6
- metadata.gz: d603a5393ff8b04fa33a0a9c9752e8b43f4d5a7dd0334702e6fbeafa32261a9a13ed887ac111740268561029af2a0e2da9411c0ceb51b659b6ffc672f21c7e1c
7
- data.tar.gz: 20f56e657f8898923ee5f218f448e45bd6a4f65ad7da863725dcb6eaa7a42733d24acac6f4b5fc7a572c95b090c49ca6a02c94c47010f3663100019aa1045d5a
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"
@@ -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 = format_number(amount, opts)
37
+ amount = FormatNumber.new(amount, opts).format
30
38
  apply_format_string(format_string, amount, currency)
31
39
  end
32
40
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Formatting
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
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.9
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