amount_formatter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzM2MjQxNjFkNWMxNDAwODhlNjdiMTAxMzE3NDU1OTJiYTYxMTM2OQ==
5
- data.tar.gz: !binary |-
6
- NGM4N2Q1NzZhZGE0NzNjZTkzYmZlNTQ0YWI3NWQ5NGRjMWM5YzBhOA==
2
+ SHA1:
3
+ metadata.gz: 0a1902659fcae5901d6fa7415fdfa58a035512b9
4
+ data.tar.gz: 8305eb10e19f97f09704b959ea857f1b625ce7c8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTczODdmMjY1NDU5NTQ0MzgxMjFkODAxYWNmMzVhNTgyZGI3YzE5NDNkNTAz
10
- N2IyZjQ1YTViZmU2ZDQxMjQxYWM0ZTIyMTI3YTliYWY3NGQ0Y2QyOGM2OWJl
11
- NmE1OTMwZWUxM2ZiODkxMjNhNjk1YzY3NmZhZDIwOTdjYWRhY2Q=
12
- data.tar.gz: !binary |-
13
- ZDFlNTIzMDhmYmMxNzQ4NjA0YjU4MTcyNzc2MWM1MTg1NDU1ODUzMzIwMWQx
14
- YjRkNjIwNTUzZDMwZDE2YTQyMTlkY2ZiNjZjMjlhM2Q5OTUwNDg3ZTQ1Mzlh
15
- NTlkNmE3ZWI5ODM2NTkwMTkzM2ZjYzFkNzc5NjkxY2I3ZjkxZGY=
6
+ metadata.gz: e451da0673166dd78d2792f4697267a25ec3e0ebbadde8852d721adb161d56cf135c3fd9c05e7bc0ea4aad786b8f920d183ba98a9e4a814d68552ac79eba5e26
7
+ data.tar.gz: 5f7f88a228a863fc0b0afb1959d78bf76e2f2bbcadd206626a25cee45e28f290044115eb37bb5f8388268ac6119db67effdea0fb9c3622fc879ae1002bd70f57
data/Gemfile CHANGED
@@ -6,8 +6,11 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
+ gem "i18n", require: false
9
10
  gem "rspec", "~> 2.8.0"
10
11
  gem "rdoc", "~> 3.12"
11
12
  gem "bundler", ">= 1.0"
12
13
  gem "jeweler", "~> 2.0.0"
13
14
  end
15
+
16
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -1,25 +1,30 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
4
+ addressable (2.3.6)
5
5
  builder (3.2.2)
6
+ codeclimate-test-reporter (0.4.1)
7
+ simplecov (>= 0.7.1, < 1.0.0)
6
8
  descendants_tracker (0.0.3)
9
+ descendants_tracker (0.0.4)
10
+ thread_safe (~> 0.3, >= 0.3.1)
7
11
  diff-lcs (1.1.3)
8
- faraday (0.8.9)
9
- multipart-post (~> 1.2.0)
10
- git (1.2.6)
11
- github_api (0.11.1)
12
+ docile (1.1.5)
13
+ faraday (0.9.0)
14
+ multipart-post (>= 1.2, < 3)
15
+ git (1.2.8)
16
+ github_api (0.12.2)
12
17
  addressable (~> 2.3)
13
- descendants_tracker (~> 0.0.1)
18
+ descendants_tracker (~> 0.0.4)
14
19
  faraday (~> 0.8, < 0.10)
15
- hashie (>= 1.2)
20
+ hashie (>= 3.3)
16
21
  multi_json (>= 1.7.5, < 2.0)
17
- nokogiri (~> 1.6.0)
22
+ nokogiri (~> 1.6.3)
18
23
  oauth2
19
- hashie (2.0.5)
20
- highline (1.6.20)
21
- httpauth (0.2.0)
22
- jeweler (2.0.0)
24
+ hashie (3.3.1)
25
+ highline (1.6.21)
26
+ i18n (0.6.11)
27
+ jeweler (2.0.1)
23
28
  builder
24
29
  bundler (>= 1.0)
25
30
  git (>= 1.2.5)
@@ -29,23 +34,21 @@ GEM
29
34
  rake
30
35
  rdoc
31
36
  json (1.8.1)
32
- jwt (0.1.10)
33
- multi_json (>= 1.5)
34
- mini_portile (0.5.2)
35
- multi_json (1.8.4)
37
+ jwt (1.0.0)
38
+ mini_portile (0.6.1)
39
+ multi_json (1.10.1)
36
40
  multi_xml (0.5.5)
37
- multipart-post (1.2.0)
38
- nokogiri (1.6.1)
39
- mini_portile (~> 0.5.0)
40
- oauth2 (0.9.2)
41
- faraday (~> 0.8)
42
- httpauth (~> 0.2)
43
- jwt (~> 0.1.4)
44
- multi_json (~> 1.0)
41
+ multipart-post (2.0.0)
42
+ nokogiri (1.6.4)
43
+ mini_portile (~> 0.6.0)
44
+ oauth2 (1.0.0)
45
+ faraday (>= 0.8, < 0.10)
46
+ jwt (~> 1.0)
47
+ multi_json (~> 1.3)
45
48
  multi_xml (~> 0.5)
46
49
  rack (~> 1.2)
47
50
  rack (1.5.2)
48
- rake (10.1.1)
51
+ rake (10.3.2)
49
52
  rdoc (3.12.2)
50
53
  json (~> 1.4)
51
54
  rspec (2.8.0)
@@ -56,12 +59,20 @@ GEM
56
59
  rspec-expectations (2.8.0)
57
60
  diff-lcs (~> 1.1.2)
58
61
  rspec-mocks (2.8.0)
62
+ simplecov (0.9.1)
63
+ docile (~> 1.1.0)
64
+ multi_json (~> 1.0)
65
+ simplecov-html (~> 0.8.0)
66
+ simplecov-html (0.8.0)
67
+ thread_safe (0.3.4)
59
68
 
60
69
  PLATFORMS
61
70
  ruby
62
71
 
63
72
  DEPENDENCIES
64
73
  bundler (>= 1.0)
74
+ codeclimate-test-reporter
75
+ i18n
65
76
  jeweler (~> 2.0.0)
66
77
  rdoc (~> 3.12)
67
78
  rspec (~> 2.8.0)
@@ -0,0 +1,46 @@
1
+ [![Build Status](https://api.shippable.com/projects/540e7b993479c5ea8f9ec1f8/badge?branchName=master)](https://app.shippable.com/projects/540e7b993479c5ea8f9ec1f8/builds/latest)
2
+ [![Code Climate](https://codeclimate.com/github/kaspernj/amount_formatter/badges/gpa.svg)](https://codeclimate.com/github/kaspernj/amount_formatter)
3
+ [![Test Coverage](https://codeclimate.com/github/kaspernj/amount_formatter/badges/coverage.svg)](https://codeclimate.com/github/kaspernj/amount_formatter)
4
+
5
+ # amount_formatter
6
+
7
+ This project is supposed to offer an alternative to ActiveSupport's number_to_currency-method, as it is fataly slow for some applications, that makes heavy use of it.
8
+
9
+ ## Installation
10
+
11
+ Add to your Gemfile and bundle:
12
+ ```ruby
13
+ gem "amount_formatter"
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Format amounts like this:
19
+ ```ruby
20
+ AmountFormatter.format(1234.12, precision: 2) #=> 1,234.12
21
+ ```
22
+
23
+ ## I18n support
24
+
25
+ Add this to an initializer:
26
+ ```ruby
27
+ AmountFormatter.locale_engine = :i18n
28
+ ```
29
+
30
+ And then use AmountFormatter as normal.
31
+
32
+ ## Contributing to amount_formatter
33
+
34
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
35
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
36
+ * Fork the project.
37
+ * Start a feature/bugfix branch.
38
+ * Commit and push until you are happy with your contribution.
39
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
40
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
41
+
42
+ ## Copyright
43
+
44
+ Copyright (c) 2014 Kasper Johansen. See LICENSE.txt for
45
+ further details.
46
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,27 +1,54 @@
1
1
  class AmountFormatter
2
- FORMAT_DEFAULT_ARGS = {:precision => 2, :separator => ".", :delimiter => ","}
3
-
2
+ FORMAT_DEFAULT_ARGS = {precision: 2}
3
+
4
+ def self.locale_engine=(engine)
5
+ @locale_engine = engine
6
+ end
7
+
4
8
  #Returns the number as a formatted string.
5
9
  def self.format(number, args = {})
10
+ separator = args[:separator] || default_separator
11
+ delimiter = args[:delimiter] || default_delimiter
12
+
6
13
  args = FORMAT_DEFAULT_ARGS.merge(args)
7
14
  number = number.to_f unless number.is_a?(Float)
8
- return sprintf("%.#{args[:precision].to_i}f", number).gsub(".", args[:separator]) if number < 1 && number > -1
15
+ return sprintf("%.#{args[:precision].to_i}f", number).gsub(".", separator) if number < 1 && number > -1
9
16
  number = sprintf("%.#{args[:precision].to_i}f", number).split(".")
10
-
17
+
11
18
  str = ""
12
19
  number[0].reverse.scan(/(.{1,3})/) do |match|
13
20
  if match[0] == "-"
14
21
  #This happens if the number is a negative number and we reach the minus-sign.
15
22
  str << match[0]
16
23
  else
17
- str << args[:delimiter] if str.length > 0
24
+ str << delimiter if str.length > 0
18
25
  str << match[0]
19
26
  end
20
27
  end
21
-
28
+
22
29
  str = str.reverse
23
- str << "#{args[:separator]}#{number[1]}" if args[:precision] > 0
24
-
30
+ str << "#{separator}#{number[1]}" if args[:precision] > 0
31
+
25
32
  return str
26
33
  end
34
+
35
+ private
36
+
37
+ def self.default_separator
38
+ if @locale_engine == :i18n && I18n.exists?("number.format.separator")
39
+ translation = I18n.t("number.format.separator").to_s.strip
40
+ return translation unless translation.empty?
41
+ end
42
+
43
+ return "."
44
+ end
45
+
46
+ def self.default_delimiter
47
+ if @locale_engine == :i18n && I18n.exists?("number.format.delimiter")
48
+ translation = I18n.t("number.format.delimiter").to_s.strip
49
+ return translation unless translation.empty?
50
+ end
51
+
52
+ return ","
53
+ end
27
54
  end
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ script:
5
+ - CODECLIMATE_REPO_TOKEN=393ae358748ba95f53b87c8c51b5a0d51e124eeeff335efd29c0ae770bd4a6b6 bundle exec rspec
6
+ notifications:
7
+ email: false
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe "i18n support for rails" do
4
+ before do
5
+ require "i18n"
6
+ AmountFormatter.locale_engine = :i18n
7
+ end
8
+
9
+ after do
10
+ AmountFormatter.locale_engine = nil
11
+ end
12
+
13
+ it "supports i18n" do
14
+ I18n.config.backend.store_translations(:da, number: {format: {separator: ",", delimiter: "."}})
15
+
16
+ I18n.with_locale :da do
17
+ AmountFormatter.format(0.1).should eq "0,10"
18
+ end
19
+ end
20
+
21
+ it "falls back when no separator set" do
22
+ I18n.with_locale :se do
23
+ AmountFormatter.format(0.1).should eq "0.10"
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amount_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ~>
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
33
  version: 2.8.0
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ~>
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: 2.8.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rdoc
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: '3.12'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ~>
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '3.12'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '1.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: jeweler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: 2.0.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ~>
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: 2.0.0
69
83
  description: Amount formatting for Ruby.
@@ -72,19 +86,21 @@ executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files:
74
88
  - LICENSE.txt
75
- - README.rdoc
89
+ - README.md
76
90
  files:
77
- - .document
78
- - .rspec
91
+ - ".document"
92
+ - ".rspec"
79
93
  - Gemfile
80
94
  - Gemfile.lock
81
95
  - LICENSE.txt
82
- - README.rdoc
96
+ - README.md
83
97
  - Rakefile
84
98
  - VERSION
85
99
  - amount_formatter.gemspec
86
100
  - lib/amount_formatter.rb
101
+ - shippable.yml
87
102
  - spec/amount_formatter_spec.rb
103
+ - spec/i18n_spec.rb
88
104
  - spec/spec_helper.rb
89
105
  homepage: http://github.com/kaspernj/amount_formatter
90
106
  licenses:
@@ -96,17 +112,17 @@ require_paths:
96
112
  - lib
97
113
  required_ruby_version: !ruby/object:Gem::Requirement
98
114
  requirements:
99
- - - ! '>='
115
+ - - ">="
100
116
  - !ruby/object:Gem::Version
101
117
  version: '0'
102
118
  required_rubygems_version: !ruby/object:Gem::Requirement
103
119
  requirements:
104
- - - ! '>='
120
+ - - ">="
105
121
  - !ruby/object:Gem::Version
106
122
  version: '0'
107
123
  requirements: []
108
124
  rubyforge_project:
109
- rubygems_version: 2.2.1
125
+ rubygems_version: 2.4.0
110
126
  signing_key:
111
127
  specification_version: 4
112
128
  summary: Amount formatting for Ruby.
@@ -1,19 +0,0 @@
1
- = amount_formatter
2
-
3
- Description goes here.
4
-
5
- == Contributing to amount_formatter
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2014 Kasper Johansen. See LICENSE.txt for
18
- further details.
19
-