amount_formatter 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/amount_formatter.gemspec +3 -3
- data/lib/amount_formatter.rb +3 -3
- data/spec/amount_formatter_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzM2MjQxNjFkNWMxNDAwODhlNjdiMTAxMzE3NDU1OTJiYTYxMTM2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGM4N2Q1NzZhZGE0NzNjZTkzYmZlNTQ0YWI3NWQ5NGRjMWM5YzBhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTczODdmMjY1NDU5NTQ0MzgxMjFkODAxYWNmMzVhNTgyZGI3YzE5NDNkNTAz
|
10
|
+
N2IyZjQ1YTViZmU2ZDQxMjQxYWM0ZTIyMTI3YTliYWY3NGQ0Y2QyOGM2OWJl
|
11
|
+
NmE1OTMwZWUxM2ZiODkxMjNhNjk1YzY3NmZhZDIwOTdjYWRhY2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDFlNTIzMDhmYmMxNzQ4NjA0YjU4MTcyNzc2MWM1MTg1NDU1ODUzMzIwMWQx
|
14
|
+
YjRkNjIwNTUzZDMwZDE2YTQyMTlkY2ZiNjZjMjlhM2Q5OTUwNDg3ZTQ1Mzlh
|
15
|
+
NTlkNmE3ZWI5ODM2NTkwMTkzM2ZjYzFkNzc5NjkxY2I3ZjkxZGY=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/amount_formatter.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: amount_formatter 0.0.
|
5
|
+
# stub: amount_formatter 0.0.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "amount_formatter"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kasper Johansen"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-02-18"
|
15
15
|
s.description = "Amount formatting for Ruby."
|
16
16
|
s.email = "k@spernj.org"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/amount_formatter.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class AmountFormatter
|
2
|
-
FORMAT_DEFAULT_ARGS = {:precision => 2, :
|
2
|
+
FORMAT_DEFAULT_ARGS = {:precision => 2, :separator => ".", :delimiter => ","}
|
3
3
|
|
4
4
|
#Returns the number as a formatted string.
|
5
5
|
def self.format(number, args = {})
|
6
6
|
args = FORMAT_DEFAULT_ARGS.merge(args)
|
7
7
|
number = number.to_f unless number.is_a?(Float)
|
8
|
-
return sprintf("%.#{args[:precision].to_i}f", number).gsub(".", args[:
|
8
|
+
return sprintf("%.#{args[:precision].to_i}f", number).gsub(".", args[:separator]) if number < 1 && number > -1
|
9
9
|
number = sprintf("%.#{args[:precision].to_i}f", number).split(".")
|
10
10
|
|
11
11
|
str = ""
|
@@ -20,7 +20,7 @@ class AmountFormatter
|
|
20
20
|
end
|
21
21
|
|
22
22
|
str = str.reverse
|
23
|
-
str << "#{args[:
|
23
|
+
str << "#{args[:separator]}#{number[1]}" if args[:precision] > 0
|
24
24
|
|
25
25
|
return str
|
26
26
|
end
|
@@ -2,7 +2,7 @@ require_relative "spec_helper"
|
|
2
2
|
|
3
3
|
describe AmountFormatter do
|
4
4
|
it "formats numbers" do
|
5
|
-
AmountFormatter.format(12345.12, :precision => 2, :
|
5
|
+
AmountFormatter.format(12345.12, :precision => 2, :separator => ",", :delimiter => ".").should eq "12.345,12"
|
6
6
|
AmountFormatter.format(12345.12).should eq "12,345.12"
|
7
7
|
AmountFormatter.format(0.1).should eq "0.10"
|
8
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amount_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|