humanize 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bin/console +15 -0
- data/humanize.gemspec +1 -1
- data/lib/humanize.rb +7 -0
- data/spec/humanize_spec.rb +33 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4e43c1d739513348d02de2ff1ff5a9f70ae5d9
|
4
|
+
data.tar.gz: 1f9b6e062f12066a8c6bc8b35ebfd2f270416cf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bac4a44f2dcbf47b79c88bedcb37abc5e08d668af8c29739fc38c80e5dd24c1e6cbebad5f8cf82865b51c3b549579e4dc9a51d38e21d68ab790e370c6815c20
|
7
|
+
data.tar.gz: 27c0004f535b4beaf57c6e0c03f2daf6679dfd424b0417ef287b40cf69501edded9b30790e97d14628eaa21751d38bfed1f72ccf4f097618733dad65804cd072
|
data/Gemfile.lock
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'humanize'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
15
|
+
|
data/humanize.gemspec
CHANGED
data/lib/humanize.rb
CHANGED
@@ -36,12 +36,19 @@ module Humanize
|
|
36
36
|
end
|
37
37
|
if self.class == Float
|
38
38
|
decimals = self.to_s.split(/\./, 2).last
|
39
|
+
has_leading_zeroes = decimals[/^0+/].to_s.length > 0
|
40
|
+
decimals_as = :digits if has_leading_zeroes
|
39
41
|
decimals_as_words = case decimals_as
|
40
42
|
when :digits then decimals.scan(/./).map { |n| SUB_ONE_THOUSAND[locale][n.to_i] }.join(' ')
|
41
43
|
when :number then decimals.to_i.humanize(:locale => locale)
|
42
44
|
end
|
43
45
|
o += ' ' + WORDS[locale][:point] + ' ' + decimals_as_words
|
44
46
|
end
|
47
|
+
if locale == :id
|
48
|
+
lots = LOTS[:id].drop(2).map{|n| n + ' '}
|
49
|
+
wrong_1000_re = /(?<=#{lots.join("|")})\s*satu ribu|^satu ribu/
|
50
|
+
o.sub!(wrong_1000_re, 'seribu')
|
51
|
+
end
|
45
52
|
o.gsub(/ +/, ' ')
|
46
53
|
end
|
47
54
|
|
data/spec/humanize_spec.rb
CHANGED
@@ -59,6 +59,26 @@ describe "Humanize" do
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
+
describe 'indonesian specific rules' do
|
63
|
+
before do
|
64
|
+
Humanize.config.default_locale = :id
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'one thousand' do
|
68
|
+
it 'equals "satu ribu" when it is not the only thousand in its thousands range' do
|
69
|
+
expect(1_101_000.humanize).to eql('satu juta seratus satu ribu')
|
70
|
+
expect(2_201_042.humanize).to eql('dua juta dua ratus satu ribu empat puluh dua')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'equals "seribu" when it is the lone thousand in its thousands range' do
|
74
|
+
expect(1_000.humanize).to eql('seribu')
|
75
|
+
expect(1_042.humanize).to eql('seribu empat puluh dua')
|
76
|
+
expect(1_001_042.humanize).to eql('satu juta seribu empat puluh dua')
|
77
|
+
expect(1_000_001_042.humanize).to eql('satu miliar seribu empat puluh dua')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
62
82
|
end
|
63
83
|
|
64
84
|
describe 'decimals_as option' do
|
@@ -73,6 +93,19 @@ describe "Humanize" do
|
|
73
93
|
expect(0.42.humanize(:decimals_as => :digits)).to eql('zero point four two')
|
74
94
|
end
|
75
95
|
|
96
|
+
describe 'when set as number' do
|
97
|
+
|
98
|
+
before do
|
99
|
+
Humanize.config.decimals_as = :number
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'reads the decimals as digits if led by zero(s)' do
|
103
|
+
expect(0.042.humanize).to eql('zero point zero four two')
|
104
|
+
expect(0.0042.humanize).to eql('zero point zero zero four two')
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
76
109
|
end
|
77
110
|
|
78
111
|
describe 'both options work together' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humanize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Chen
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- Wordlist.source
|
84
84
|
- bench.rb
|
85
|
+
- bin/console
|
85
86
|
- bin/run_mutant
|
86
87
|
- humanize.gemspec
|
87
88
|
- lib/humanize.rb
|