inflections 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inflections.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Celis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,41 @@
1
+ # Inflections
2
+
3
+ This gem is to remove the cruft from ActiveSupport's inflections and provide a more sane set of defaults for Ruby/Rails applications.
4
+
5
+ At the time of this gem's publication, the list of inflections in ActiveSupport is a mess. It is riddled with special cases such as a special pluralization rule for "octopus" and "virus", even though they follow a regular rule (as octopi and viri are disputed terms). Similar pluralization rules exist for "ox", "quiz", "mouse", "louse", etc.
6
+
7
+ Many of the special cases that ActiveSupport defines will not see the light of day in an application. Other rules exist that are actually gramatical exceptions, such as changing "f" to a "v" when encountered at the end of the word (which then requires even more rules to fix special words such as "drive", "safe", "hive", etc.). And, of course, who can forget the special pluralization of "cow" to the archaic term of Scottish origin, "kine" (the plural of "kye")?
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'inflections'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ If you're using Rails, you're done. The default inflections defined in ActiveSupport will be overwritten, and you can continue to define your own special cases in `config/intializers/inflections.rb`.
26
+
27
+ Otherwise, wherever you need 'em:
28
+
29
+ ```ruby
30
+ require 'inflections'
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Please note that pull requests will only be accepted for rules that are in error or a potentially missed rule. If your change is an exception to an existing rule, that exception must occur _frequently_ and must involved words used more frequently than the regular plurals. If your change is an irregularity, it must be a word that is arguably _frequently_ encountered in applications that would use ActiveSupport.
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`) with tests
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/inflections/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['David Celis']
6
+ gem.email = ['david@davidcelis.com']
7
+ gem.description = %q{A better set of singularization and pluralization rules for Ruby/Rails applications using ActiveSupport.}
8
+ gem.summary = %q{Sane inflection rules for ActiveSupport.}
9
+ gem.homepage = 'https://github.com/davidcelis/inflections'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'inflections'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Inflections::VERSION
17
+
18
+ gem.add_development_dependency 'bundler'
19
+ gem.add_development_dependency 'minitest'
20
+
21
+ gem.add_dependency 'activesupport', '>= 2.2.1'
22
+ end
@@ -0,0 +1,74 @@
1
+ require 'inflections'
2
+ require 'minitest/autorun'
3
+
4
+ class TestInflections < MiniTest::Unit::TestCase
5
+ def test_regular_plurals
6
+ assert_equal 'dogs', 'dog'.pluralize
7
+ assert_equal 'dog', 'dogs'.singularize
8
+
9
+ assert_equal 'days', 'day'.pluralize
10
+ assert_equal 'day', 'days'.singularize
11
+
12
+ assert_equal 'tests', 'test'.pluralize
13
+ assert_equal 'test', 'tests'.singularize
14
+ end
15
+
16
+ def test_sibilant_sounds
17
+ assert_equal 'addresses', 'address'.pluralize
18
+ assert_equal 'address', 'addresses'.singularize
19
+
20
+ assert_equal 'phases', 'phase'.pluralize
21
+ # Can't assume whether words that end with 'es' remove the 'es' or just 's'
22
+ # So I went with the case that seemed more reasonable given sibilant sounds
23
+ #
24
+ # assert_equal 'phase', 'phases'.singularize
25
+
26
+ assert_equal 'buzzes', 'buzz'.pluralize
27
+ assert_equal 'buzz', 'buzzes'.singularize
28
+
29
+ assert_equal 'boxes', 'box'.pluralize
30
+ assert_equal 'box', 'boxes'.singularize
31
+
32
+ assert_equal 'benches', 'bench'.pluralize
33
+ assert_equal 'bench', 'benches'.singularize
34
+
35
+ assert_equal 'dishes', 'dish'.pluralize
36
+ assert_equal 'dish', 'dishes'.singularize
37
+ end
38
+
39
+ def test_oes_rule
40
+ assert_equal 'heroes', 'hero'.pluralize
41
+ assert_equal 'hero', 'heroes'.singularize
42
+
43
+ assert_equal 'igloos', 'igloo'.pluralize
44
+ assert_equal 'igloo', 'igloos'.singularize
45
+ end
46
+
47
+ def test_ies_rule
48
+ assert_equal 'berries', 'berry'.pluralize
49
+ assert_equal 'berry', 'berries'.singularize
50
+
51
+ assert_equal 'days', 'day'.pluralize
52
+ assert_equal 'day', 'days'.singularize
53
+ end
54
+
55
+ def test_irregulars
56
+ assert_equal 'children', 'child'.pluralize
57
+ assert_equal 'child', 'children'.singularize
58
+
59
+ assert_equal 'people', 'person'.pluralize
60
+ assert_equal 'person', 'people'.singularize
61
+
62
+ assert_equal 'selves', 'self'.pluralize
63
+ assert_equal 'self', 'selves'.singularize
64
+ end
65
+
66
+ def test_uncountables
67
+ assert_equal 'series', 'series'.pluralize
68
+ assert_equal 'series', 'series'.singularize
69
+ end
70
+
71
+ def test_stupid_inflections_removed
72
+ assert_equal 'cows', 'cow'.pluralize
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Inflections
4
+ end
5
+
6
+ ActiveSupport::Inflector.inflections do |inflect|
7
+ inflect.clear
8
+
9
+ inflect.plural(/$/, 's')
10
+ inflect.plural(/([sxz]|[cs]h)$/i, '\1es')
11
+ inflect.plural(/([^aeiouy]o)$/i, '\1es')
12
+ inflect.plural(/([^aeiouy])y$/i, '\1ies')
13
+
14
+ inflect.singular(/s$/i, '')
15
+ inflect.singular(/(ss)$/i, '\1')
16
+ inflect.singular(/([sxz]|[cs]h)es/, '\1')
17
+ inflect.singular(/([^aeiouy]o)es$/, '\1')
18
+ inflect.singular(/([^aeiouy])ies$/i, '\1y')
19
+
20
+ inflect.irregular('child', 'children')
21
+ inflect.irregular('person', 'people')
22
+ inflect.irregular('self', 'selves')
23
+
24
+ inflect.uncountable(%w(series))
25
+ end
@@ -0,0 +1,3 @@
1
+ module Inflections
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inflections
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Celis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.2.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.1
62
+ description: A better set of singularization and pluralization rules for Ruby/Rails
63
+ applications using ActiveSupport.
64
+ email:
65
+ - david@davidcelis.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.markdown
74
+ - Rakefile
75
+ - inflections.gemspec
76
+ - inflections_test.rb
77
+ - lib/inflections.rb
78
+ - lib/inflections/version.rb
79
+ homepage: https://github.com/davidcelis/inflections
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.23
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Sane inflection rules for ActiveSupport.
103
+ test_files: []
104
+ has_rdoc: