pluralize 0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/.yardoc +0 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.rdoc +36 -5
- data/Rakefile +66 -27
- data/VERSION +1 -0
- data/lib/pluralize.rb +1 -0
- data/lib/pluralize/active_support/inflector.rb +2 -6
- data/pluralize.gemspec +65 -0
- data/{test → spec}/config/inflections.rb +1 -1
- data/spec/pluralize_spec.rb +61 -0
- data/spec/spec_helper.rb +9 -0
- metadata +47 -16
- data/init.rb +0 -1
- data/install.rb +0 -1
- data/tasks/pluralize_tasks.rake +0 -4
- data/test/pluralize_test.rb +0 -8
- data/test/test_helper.rb +0 -3
- data/uninstall.rb +0 -1
data/.document
ADDED
data/.gitignore
ADDED
data/.yardoc
ADDED
Binary file
|
data/{MIT-LICENSE → LICENSE}
RENAMED
data/README.rdoc
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
|
1
|
+
== Pluralize - Better pluralization for non-english languages
|
2
2
|
|
3
|
-
|
3
|
+
Languages vary in how they handle plurals of nouns or unit expressions ("hours", "meters", and so on). Some languages have two forms, like English; some languages have only a single form; and some languages have multiple forms.
|
4
4
|
|
5
|
-
|
5
|
+
Read more at: http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
|
6
6
|
|
7
|
-
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
The gem is hosted on gemcutter, so if you haven’t already, add it as a gem source:
|
10
|
+
|
11
|
+
sudo gem sources -a http://gemcutter.org/
|
12
|
+
|
13
|
+
Then install the Formtastic gem:
|
14
|
+
|
15
|
+
sudo gem install pluralize
|
16
|
+
|
17
|
+
== Configuration
|
8
18
|
|
9
19
|
ActiveSupport::Inflector.inflections do |inflect|
|
10
20
|
inflect.proc :pl, lambda{|count, singular, inflections|
|
@@ -18,7 +28,7 @@ http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
|
|
18
28
|
}
|
19
29
|
|
20
30
|
inflect.plural "chleb", :few => "chleby", :other => "chlebów", :proc => :pl
|
21
|
-
inflect.plural "szklanka", :few => "szklanki", :other => "szklanek" #
|
31
|
+
inflect.plural "szklanka", :few => "szklanki", :other => "szklanek" # use first defined proc
|
22
32
|
inflect.plural "one potatoe",
|
23
33
|
:two => "two potatoes",
|
24
34
|
:three => "three potatoes",
|
@@ -41,5 +51,26 @@ http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
|
|
41
51
|
}
|
42
52
|
end
|
43
53
|
|
54
|
+
== Usage
|
55
|
+
|
56
|
+
ActiveSupport::Inflector.pluralize("chleb", 1) # => chleb
|
57
|
+
ActiveSupport::Inflector.pluralize("chleb", 2) # => chleby
|
58
|
+
"chleb".pluralize # => chleby
|
59
|
+
ActiveSupport::Inflector.pluralize("chleb", 5) # => chlebów
|
60
|
+
ActiveSupport::Inflector.pluralize("one potatoe", 7) # => seven potatoes
|
61
|
+
ActiveSupport::Inflector.pluralize("one potatoe", 10) # => more!
|
62
|
+
|
63
|
+
# for other words it behaves like before
|
64
|
+
ActiveSupport::Inflector.pluralize("word") # => words
|
65
|
+
ActiveSupport::Inflector.pluralize("octopus") # => octopi
|
66
|
+
"person".pluralize # => people
|
67
|
+
|
68
|
+
#in your views
|
69
|
+
|
70
|
+
<%= pluralize(3, "chleb") %> # => chleby
|
71
|
+
|
72
|
+
== Author
|
73
|
+
|
74
|
+
Marcin Ciunelis marcin.ciunelis@gmail.com
|
44
75
|
|
45
76
|
Copyright (c) 2009 G-Forces Polska, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,38 +1,77 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "pluralize"
|
8
|
+
gem.summary = "Better pluralization for non-english languages"
|
9
|
+
gem.email = "marcin.ciunelis@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/gforces/pluralize"
|
11
|
+
gem.authors = ["Marcin Ciunelis"]
|
12
|
+
gem.add_development_dependency "bacon", ">= 0"
|
13
|
+
gem.add_development_dependency "yard", ">= 0"
|
14
|
+
gem.add_development_dependency "activesupport", ">= 0"
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
7
20
|
|
8
|
-
|
9
|
-
Rake::TestTask.new(:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
t.verbose = true
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
25
|
+
spec.verbose = true
|
14
26
|
end
|
15
27
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |spec|
|
31
|
+
spec.libs << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
23
39
|
end
|
24
40
|
|
41
|
+
task :spec => :check_dependencies
|
42
|
+
|
25
43
|
begin
|
26
|
-
require '
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
require 'reek/rake_task'
|
45
|
+
Reek::RakeTask.new do |t|
|
46
|
+
t.fail_on_error = true
|
47
|
+
t.verbose = false
|
48
|
+
t.source_files = 'lib/**/*.rb'
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
task :reek do
|
52
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
begin
|
57
|
+
require 'roodi'
|
58
|
+
require 'roodi_task'
|
59
|
+
RoodiTask.new do |t|
|
60
|
+
t.verbose = false
|
34
61
|
end
|
35
|
-
Jeweler::GemcutterTasks.new
|
36
62
|
rescue LoadError
|
37
|
-
|
63
|
+
task :roodi do
|
64
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
task :default => :spec
|
69
|
+
|
70
|
+
begin
|
71
|
+
require 'yard'
|
72
|
+
YARD::Rake::YardocTask.new
|
73
|
+
rescue LoadError
|
74
|
+
task :yardoc do
|
75
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
76
|
+
end
|
38
77
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/lib/pluralize.rb
CHANGED
@@ -11,8 +11,8 @@ module ActiveSupport
|
|
11
11
|
if result == rule
|
12
12
|
if replacement.has_key?(:proc) && replacement[:proc].is_a?(Proc)
|
13
13
|
proc = replacement[:proc]
|
14
|
-
elsif replacement.has_key?(:proc) && inflections.procs[replacement
|
15
|
-
proc = inflections.procs[replacement
|
14
|
+
elsif replacement.has_key?(:proc) && inflections.procs[replacement[:proc].to_sym].is_a?(Proc)
|
15
|
+
proc = inflections.procs[replacement[:proc].to_sym]
|
16
16
|
elsif inflections.default_proc.is_a?(Proc)
|
17
17
|
proc = inflections.default_proc
|
18
18
|
end
|
@@ -32,10 +32,6 @@ module ActiveSupport
|
|
32
32
|
class Inflections
|
33
33
|
attr_reader :procs
|
34
34
|
|
35
|
-
# def initialize
|
36
|
-
# @plurals, @singulars, @uncountables, @humans, @procs = [], [], [], [], {}
|
37
|
-
# end
|
38
|
-
|
39
35
|
def proc(locale, proc)
|
40
36
|
@procs = {} if @procs.nil?
|
41
37
|
@procs[locale.to_sym] = proc
|
data/pluralize.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pluralize}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marcin Ciunelis"]
|
12
|
+
s.date = %q{2009-10-29}
|
13
|
+
s.email = %q{marcin.ciunelis@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
".yardoc",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/pluralize.rb",
|
27
|
+
"lib/pluralize/action_view/helpers/text_helper.rb",
|
28
|
+
"lib/pluralize/active_support/inflector.rb",
|
29
|
+
"lib/pluralize/config/inflections.rb",
|
30
|
+
"pluralize.gemspec",
|
31
|
+
"spec/config/inflections.rb",
|
32
|
+
"spec/pluralize_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/gforces/pluralize}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Better pluralization for non-english languages}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/config/inflections.rb",
|
42
|
+
"spec/pluralize_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<bacon>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
56
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<bacon>, [">= 0"])
|
61
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
62
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -10,7 +10,7 @@ ActiveSupport::Inflector.inflections do |inflect|
|
|
10
10
|
}
|
11
11
|
|
12
12
|
inflect.plural "chleb", :few => "chleby", :other => "chlebów", :proc => :pl
|
13
|
-
inflect.plural "szklanka", :few => "szklanki", :other => "szklanek" #
|
13
|
+
inflect.plural "szklanka", :few => "szklanki", :other => "szklanek" # use first defined proc
|
14
14
|
inflect.plural "one potatoe",
|
15
15
|
:two => "two potatoes",
|
16
16
|
:three => "three potatoes",
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Pluralize" do
|
4
|
+
it "should pluralize polish word \"chleb\"" do
|
5
|
+
{
|
6
|
+
0 => 'chlebów',
|
7
|
+
1 => 'chleb',
|
8
|
+
2 => 'chleby',
|
9
|
+
3 => 'chleby',
|
10
|
+
4 => 'chleby',
|
11
|
+
5 => 'chlebów',
|
12
|
+
6 => 'chlebów',
|
13
|
+
11 => 'chlebów',
|
14
|
+
22 => 'chleby',
|
15
|
+
221 => 'chlebów'
|
16
|
+
}.each do |count, plural_form|
|
17
|
+
ActiveSupport::Inflector.pluralize("chleb", count).should.equal plural_form
|
18
|
+
end
|
19
|
+
end
|
20
|
+
it "should pluralize polish word \"szklanka\"" do
|
21
|
+
{
|
22
|
+
0 => 'szklanek',
|
23
|
+
1 => 'szklanka',
|
24
|
+
2 => 'szklanki',
|
25
|
+
3 => 'szklanki',
|
26
|
+
4 => 'szklanki',
|
27
|
+
5 => 'szklanek',
|
28
|
+
6 => 'szklanek',
|
29
|
+
11 => 'szklanek',
|
30
|
+
22 => 'szklanki',
|
31
|
+
221 => 'szklanek'
|
32
|
+
}.each do |count, plural_form|
|
33
|
+
ActiveSupport::Inflector.pluralize("szklanka", count).should.equal plural_form
|
34
|
+
end
|
35
|
+
end
|
36
|
+
it "should pluralize english word \"word\"" do
|
37
|
+
{
|
38
|
+
0 => 'words',
|
39
|
+
1 => 'words',
|
40
|
+
2 => 'words',
|
41
|
+
3 => 'words',
|
42
|
+
4 => 'words',
|
43
|
+
5 => 'words',
|
44
|
+
6 => 'words',
|
45
|
+
11 => 'words',
|
46
|
+
22 => 'words',
|
47
|
+
221 => 'words',
|
48
|
+
nil => 'words'
|
49
|
+
}.each do |count, plural_form|
|
50
|
+
ActiveSupport::Inflector.pluralize("word", count).should.equal plural_form
|
51
|
+
end
|
52
|
+
ActiveSupport::Inflector.pluralize("octopus").should.equal "octopi"
|
53
|
+
ActiveSupport::Inflector.pluralize("person").should.equal "people"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should pluralize strings" do
|
57
|
+
"chleb".pluralize.should.equal "chleby"
|
58
|
+
"chleb".pluralize(10).should.equal "chlebów"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluralize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Ciunelis
|
@@ -9,10 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-29 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bacon
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
16
45
|
description:
|
17
46
|
email: marcin.ciunelis@gmail.com
|
18
47
|
executables: []
|
@@ -20,22 +49,24 @@ executables: []
|
|
20
49
|
extensions: []
|
21
50
|
|
22
51
|
extra_rdoc_files:
|
52
|
+
- LICENSE
|
23
53
|
- README.rdoc
|
24
54
|
files:
|
25
|
-
-
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- .yardoc
|
58
|
+
- LICENSE
|
26
59
|
- README.rdoc
|
27
60
|
- Rakefile
|
28
|
-
-
|
29
|
-
- install.rb
|
61
|
+
- VERSION
|
30
62
|
- lib/pluralize.rb
|
31
63
|
- lib/pluralize/action_view/helpers/text_helper.rb
|
32
64
|
- lib/pluralize/active_support/inflector.rb
|
33
65
|
- lib/pluralize/config/inflections.rb
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
- uninstall.rb
|
66
|
+
- pluralize.gemspec
|
67
|
+
- spec/config/inflections.rb
|
68
|
+
- spec/pluralize_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
39
70
|
has_rdoc: true
|
40
71
|
homepage: http://github.com/gforces/pluralize
|
41
72
|
licenses: []
|
@@ -63,8 +94,8 @@ rubyforge_project:
|
|
63
94
|
rubygems_version: 1.3.5
|
64
95
|
signing_key:
|
65
96
|
specification_version: 3
|
66
|
-
summary:
|
97
|
+
summary: Better pluralization for non-english languages
|
67
98
|
test_files:
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
99
|
+
- spec/config/inflections.rb
|
100
|
+
- spec/pluralize_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'pluralize'
|
data/install.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Install hook code here
|
data/tasks/pluralize_tasks.rake
DELETED
data/test/pluralize_test.rb
DELETED
data/test/test_helper.rb
DELETED
data/uninstall.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Uninstall hook code here
|