inflecto 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.
Files changed (40) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +24 -0
  4. data/Changelog.md +7 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.devtools +66 -0
  7. data/Guardfile +18 -0
  8. data/LICENSE +20 -0
  9. data/README.md +46 -0
  10. data/Rakefile +5 -0
  11. data/TODO +1 -0
  12. data/config/flay.yml +3 -0
  13. data/config/flog.yml +2 -0
  14. data/config/mutant.yml +3 -0
  15. data/config/roodi.yml +20 -0
  16. data/config/site.reek +95 -0
  17. data/config/yardstick.yml +2 -0
  18. data/inflecto.gemspec +16 -0
  19. data/lib/inflecto.rb +307 -0
  20. data/lib/inflecto/defaults.rb +58 -0
  21. data/lib/inflecto/inflections.rb +206 -0
  22. data/spec/integration/inflector_spec.rb +7 -0
  23. data/spec/rcov.opts +7 -0
  24. data/spec/shared/command_method_behavior.rb +7 -0
  25. data/spec/shared/each_method_behaviour.rb +15 -0
  26. data/spec/shared/hash_method_behavior.rb +17 -0
  27. data/spec/shared/idempotent_method_behavior.rb +7 -0
  28. data/spec/shared/invertible_method_behaviour.rb +9 -0
  29. data/spec/shared/mutator_behavior.rb +44 -0
  30. data/spec/spec_helper.rb +10 -0
  31. data/spec/unit/inflector/class_methods/camelize_spec.rb +21 -0
  32. data/spec/unit/inflector/class_methods/classify_spec.rb +15 -0
  33. data/spec/unit/inflector/class_methods/demodulize_spec.rb +13 -0
  34. data/spec/unit/inflector/class_methods/foreign_key_spec.rb +13 -0
  35. data/spec/unit/inflector/class_methods/humanize_spec.rb +14 -0
  36. data/spec/unit/inflector/class_methods/pluralize_spec.rb +194 -0
  37. data/spec/unit/inflector/class_methods/singularize_spec.rb +153 -0
  38. data/spec/unit/inflector/class_methods/tabelize_spec.rb +27 -0
  39. data/spec/unit/inflector/class_methods/underscore_spec.rb +21 -0
  40. metadata +99 -0
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto do
4
+ describe '.foreign_key' do
5
+ it 'adds _id to downcased string: Message => message_id' do
6
+ Inflecto.foreign_key('Message').should == 'message_id'
7
+ end
8
+
9
+ it 'demodulizes string first: Admin::Post => post_id' do
10
+ Inflecto.foreign_key('Admin::Post').should == 'post_id'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto do
4
+ describe '.humanize' do
5
+ it 'replaces _ with space: humanizes employee_salary as Employee salary' do
6
+ Inflecto.humanize('employee_salary').should == 'Employee salary'
7
+ end
8
+
9
+ it 'strips _id endings: humanizes author_id as Author' do
10
+ Inflecto.humanize('author_id').should == 'Author'
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto, '.pluralize' do
4
+
5
+ SINGULAR_TO_PLURAL = {
6
+ 'equipment' => 'equipment',
7
+ 'information' => 'information',
8
+ 'money' => 'money',
9
+ 'species' => 'species',
10
+ 'series' => 'series',
11
+ 'fish' => 'fish',
12
+ 'sheep' => 'sheep',
13
+ 'news' => 'news',
14
+ 'matrix' => 'matrices',
15
+ 'life' => 'lives',
16
+ 'wife' => 'wives',
17
+ 'alias' => 'aliases',
18
+ 'status' => 'statuses',
19
+ 'axis' => 'axes',
20
+ 'crisis' => 'crises',
21
+ 'testis' => 'testes',
22
+ 'child' => 'children',
23
+ 'person' => 'people',
24
+ 'tomato' => 'tomatoes',
25
+ 'buffalo' => 'buffaloes',
26
+ 'quiz' => 'quizzes',
27
+ 'vertex' => 'vertices',
28
+ 'index' => 'indices',
29
+ 'ox' => 'oxen',
30
+ 'mouse' => 'mice',
31
+ 'louse' => 'lice',
32
+ 'thesis' => 'theses',
33
+ 'analysis' => 'analyses',
34
+ 'octopus' => 'octopi',
35
+ 'grass' => 'grass',
36
+ 'drive' => 'drives',
37
+ # ==== bugs, typos and reported issues
38
+
39
+ # ==== rules and most common cases
40
+
41
+ 'forum' => 'forums',
42
+ 'hive' => 'hives',
43
+ 'athlete' => 'athletes',
44
+ 'dwarf' => 'dwarves',
45
+ 'man' => 'men',
46
+ 'woman' => 'women',
47
+ 'sportsman' => 'sportsmen',
48
+ 'branch' => 'branches',
49
+ 'crunch' => 'crunches',
50
+ 'trash' => 'trashes',
51
+ 'mash' => 'mashes',
52
+ 'cross' => 'crosses',
53
+ 'erratum' => 'errata',
54
+ # FIXME: add -ia => -ium cases
55
+ # FIXME: add -ra => -rum cases
56
+ 'ray' => 'rays',
57
+ 'spray' => 'sprays',
58
+ # Merriam-Webster dictionary says
59
+ # preys is correct, too.
60
+ 'prey' => 'preys',
61
+ 'toy' => 'toys',
62
+ 'joy' => 'joys',
63
+ 'buy' => 'buys',
64
+ 'guy' => 'guys',
65
+ 'cry' => 'cries',
66
+ 'fly' => 'flies',
67
+ 'fox' => 'foxes',
68
+ 'elf' => 'elves',
69
+ 'shelf' => 'shelves',
70
+ 'cat' => 'cats',
71
+ 'rat' => 'rats',
72
+ 'rose' => 'roses',
73
+ 'project' => 'projects',
74
+ 'post' => 'posts',
75
+ 'article' => 'articles',
76
+ 'location' => 'locations',
77
+ 'friend' => 'friends',
78
+ 'link' => 'links',
79
+ 'url' => 'urls',
80
+ 'account' => 'accounts',
81
+ 'server' => 'servers',
82
+ 'fruit' => 'fruits',
83
+ 'map' => 'maps',
84
+ 'income' => 'incomes',
85
+ 'ping' => 'pings',
86
+ 'event' => 'events',
87
+ 'proof' => 'proofs',
88
+ 'typo' => 'typos',
89
+ 'attachment' => 'attachments',
90
+ 'download' => 'downloads',
91
+ 'asset' => 'assets',
92
+ 'job' => 'jobs',
93
+ 'city' => 'cities',
94
+ 'package' => 'packages',
95
+ 'commit' => 'commits',
96
+ 'version' => 'versions',
97
+ 'document' => 'documents',
98
+ 'edition' => 'editions',
99
+ 'movie' => 'movies',
100
+ 'song' => 'songs',
101
+ 'invoice' => 'invoices',
102
+ 'product' => 'products',
103
+ 'book' => 'books',
104
+ 'ticket' => 'tickets',
105
+ 'game' => 'games',
106
+ 'tournament' => 'tournaments',
107
+ 'prize' => 'prizes',
108
+ 'price' => 'prices',
109
+ 'installation' => 'installations',
110
+ 'date' => 'dates',
111
+ 'schedule' => 'schedules',
112
+ 'arena' => 'arenas',
113
+ 'spam' => 'spams',
114
+ 'bus' => 'buses',
115
+ 'rice' => 'rice',
116
+
117
+ # Some specs from Rails
118
+ 'search' => 'searches',
119
+ 'switch' => 'switches',
120
+ 'fix' => 'fixes',
121
+ 'box' => 'boxes',
122
+ 'process' => 'processes',
123
+ 'address' => 'addresses',
124
+ 'case' => 'cases',
125
+ 'stack' => 'stacks',
126
+ 'wish' => 'wishes',
127
+ 'category' => 'categories',
128
+ 'query' => 'queries',
129
+ 'ability' => 'abilities',
130
+ 'agency' => 'agencies',
131
+ 'archive' => 'archives',
132
+ 'safe' => 'saves',
133
+ 'half' => 'halves',
134
+ 'move' => 'moves',
135
+ 'salesperson' => 'salespeople',
136
+ 'spokesman' => 'spokesmen',
137
+ 'basis' => 'bases',
138
+ 'diagnosis' => 'diagnoses',
139
+ 'diagnosis_a' => 'diagnosis_as',
140
+ 'datum' => 'data',
141
+ 'medium' => 'media',
142
+ 'node_child' => 'node_children',
143
+ 'experience' => 'experiences',
144
+ 'day' => 'days',
145
+ 'comment' => 'comments',
146
+ 'foobar' => 'foobars',
147
+ 'newsletter' => 'newsletters',
148
+ 'old_news' => 'old_news',
149
+ 'perspective' => 'perspectives',
150
+ 'photo' => 'photos',
151
+ 'status_code' => 'status_codes',
152
+ 'house' => 'houses',
153
+ 'portfolio' => 'portfolios',
154
+ 'matrix_fu' => 'matrix_fus',
155
+ 'axis' => 'axes',
156
+ 'shoe' => 'shoes',
157
+ 'horse' => 'horses',
158
+ 'edge' => 'edges',
159
+
160
+ }
161
+
162
+ # Missing rule or exception?
163
+ PENDING = {
164
+ 'cow' => 'cows', # 'kine' is archaic and nobody uses it
165
+ 'virus' => 'viruses',
166
+ 'torpedo' => 'torpedoes',
167
+ 'Swiss' => 'Swiss',
168
+ 'goose' => 'geese',
169
+ 'milk' => 'milk',
170
+ 'plus' => 'plusses',
171
+ 'thesaurus' => 'thesauri',
172
+ 'thief' => 'thieves',
173
+ 'hovercraft' => 'hovercraft',
174
+ 'zero' => 'zeroes',
175
+ 'rain' => 'rain',
176
+ 'cactus' => 'cacti',
177
+ 'moose' => 'moose',
178
+ 'criterion' => 'criteria',
179
+ 'potato' => 'potatoes',
180
+ 'phenomenon' => 'phenomena',
181
+ 'hero' => 'heroes',
182
+ }
183
+
184
+ PENDING.each do |singular, plural|
185
+ pending "missing exception or rule for #{singular} => #{plural}"
186
+ end
187
+
188
+ SINGULAR_TO_PLURAL.each do |singular, plural|
189
+ it "pluralizes #{singular} => #{plural}" do
190
+ Inflecto.pluralize(singular).should eql(plural)
191
+ end
192
+ end
193
+
194
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto, '#singular' do
4
+ # ==== exceptional cases
5
+
6
+ PLURAL_TO_SINGULAR = {
7
+ 'equipment' => 'equipment',
8
+ 'mysql' => 'mysql',
9
+ 'information' => 'information',
10
+ 'money' => 'money',
11
+ 'species' => 'species',
12
+ 'series' => 'series',
13
+ 'fish' => 'fish',
14
+ 'sheep' => 'sheep',
15
+ 'news' => 'news',
16
+ 'rain' => 'rain',
17
+ 'milk' => 'milk',
18
+ 'moose' => 'moose',
19
+ 'hovercraft' => 'hovercraft',
20
+ 'matrices' => 'matrix',
21
+ 'lives' => 'life',
22
+ 'wives' => 'wife',
23
+ 'aliases' => 'alias',
24
+ 'statuses' => 'status',
25
+ 'axes' => 'axis',
26
+ 'crises' => 'crisis',
27
+ 'testes' => 'testis',
28
+ 'children' => 'child',
29
+ 'people' => 'person',
30
+ 'potatoes' => 'potato',
31
+ 'tomatoes' => 'tomato',
32
+ 'buffaloes' => 'buffalo',
33
+ 'torpedoes' => 'torpedo',
34
+ 'quizzes' => 'quiz',
35
+ 'vertices' => 'vertex',
36
+ 'indices' => 'index',
37
+ 'indexes' => 'index',
38
+ 'oxen' => 'ox',
39
+ 'mice' => 'mouse',
40
+ 'lice' => 'louse',
41
+ 'theses' => 'thesis',
42
+ 'analyses' => 'analysis',
43
+ 'octopi' => 'octopus',
44
+ 'grass' => 'grass',
45
+ # ==== bugs, typos and reported issues
46
+
47
+ # ==== rules
48
+
49
+ 'forums' => 'forum',
50
+ 'hives' => 'hive',
51
+ 'athletes' => 'athlete',
52
+ 'dwarves' => 'dwarf',
53
+ 'heroes' => 'hero',
54
+ 'zeroes' => 'zero',
55
+ 'men' => 'man',
56
+ 'women' => 'woman',
57
+ 'sportsmen' => 'sportsman',
58
+ 'branches' => 'branch',
59
+ 'crunches' => 'crunch',
60
+ 'trashes' => 'trash',
61
+ 'mashes' => 'mash',
62
+ 'crosses' => 'cross',
63
+ 'errata' => 'erratum',
64
+ # FIXME: add -ia => -ium cases
65
+
66
+ # FIXME: add -ra => -rum cases
67
+
68
+ 'rays' => 'ray',
69
+ 'sprays' => 'spray',
70
+ # Merriam-Webster dictionary says
71
+ # preys is correct, too.
72
+ 'preys' => 'prey',
73
+ 'toys' => 'toy',
74
+ 'joys' => 'joy',
75
+ 'buys' => 'buy',
76
+ 'guys' => 'guy',
77
+ 'cries' => 'cry',
78
+ 'flies' => 'fly',
79
+ 'foxes' => 'fox',
80
+ 'elves' => 'elf',
81
+ 'shelves' => 'shelf',
82
+ 'cats' => 'cat',
83
+ 'rats' => 'rat',
84
+ 'roses' => 'rose',
85
+ 'projects' => 'project',
86
+ 'posts' => 'post',
87
+ 'articles' => 'article',
88
+ 'locations' => 'location',
89
+ 'friends' => 'friend',
90
+ 'links' => 'link',
91
+ 'urls' => 'url',
92
+ 'accounts' => 'account',
93
+ 'servers' => 'server',
94
+ 'fruits' => 'fruit',
95
+ 'maps' => 'map',
96
+ 'incomes' => 'income',
97
+ 'pings' => 'ping',
98
+ 'events' => 'event',
99
+ 'proofs' => 'proof',
100
+ 'typos' => 'typo',
101
+ 'attachments' => 'attachment',
102
+ 'downloads' => 'download',
103
+ 'assets' => 'asset',
104
+ 'jobs' => 'job',
105
+ 'cities' => 'city',
106
+ 'packages' => 'package',
107
+ 'commits' => 'commit',
108
+ 'versions' => 'version',
109
+ 'documents' => 'document',
110
+ 'editions' => 'edition',
111
+ 'movies' => 'movie',
112
+ 'songs' => 'song',
113
+ 'invoices' => 'invoice',
114
+ 'products' => 'product',
115
+ 'books' => 'book',
116
+ 'tickets' => 'ticket',
117
+ 'games' => 'game',
118
+ 'tournaments' => 'tournament',
119
+ 'prizes' => 'prize',
120
+ 'prices' => 'price',
121
+ 'installations' => 'installation',
122
+ 'dates' => 'date',
123
+ 'schedules' => 'schedule',
124
+ 'arenas' => 'arena',
125
+ 'spams' => 'spam',
126
+ 'rice' => 'rice'
127
+ }
128
+
129
+ # Missing exceptions or missing rules?
130
+ PENDING = {
131
+ 'cacti' => 'cactus',
132
+ 'cactuses' => 'cactus',
133
+ 'thesauri' => 'thesaurus',
134
+ 'geese' => 'goose',
135
+ 'phenomena' => 'phenomenon',
136
+ 'Swiss' => 'Swiss',
137
+ 'drives' => 'drive',
138
+ 'pluses' => 'plus',
139
+ 'thieves' => 'thief',
140
+ 'criteria' => 'criterion',
141
+ 'postgres' => 'postgres'
142
+ }
143
+
144
+ PENDING.each do |plural, singular|
145
+ pending "missing rule or exception for #{plural} => #{singular}"
146
+ end
147
+
148
+ PLURAL_TO_SINGULAR.each do |plural, singular|
149
+ it "should signularize #{plural} => #{singular}" do
150
+ Inflecto.singularize(plural).should eql(singular)
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto, '.tableize' do
4
+ it 'pluralizes last word in snake_case strings: fancy_category => fancy_categories' do
5
+ Inflecto.tableize('fancy_category').should == 'fancy_categories'
6
+ end
7
+
8
+ it 'underscores CamelCase strings before pluralization: enlarged_testis => enlarged_testes' do
9
+ Inflecto.tableize('enlarged_testis').should == 'enlarged_testes'
10
+ end
11
+
12
+ it 'underscores CamelCase strings before pluralization: FancyCategory => fancy_categories' do
13
+ Inflecto.tableize('FancyCategory').should == 'fancy_categories'
14
+ end
15
+
16
+ it 'underscores CamelCase strings before pluralization: EnlargedTestis => enlarged_testes' do
17
+ Inflecto.tableize('EnlargedTestis').should == 'enlarged_testes'
18
+ end
19
+
20
+ it 'replaces :: with underscores: Fancy::Category => fancy_categories' do
21
+ Inflecto.tableize('Fancy::Category').should == 'fancy_categories'
22
+ end
23
+
24
+ it 'underscores CamelCase strings before pluralization: Enlarged::Testis => enlarged_testes' do
25
+ Inflecto.tableize('Enlarged::Testis').should == 'enlarged_testes'
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Inflecto do
4
+ describe '.underscore' do
5
+ it 'underscores DataMapper as data_mapper' do
6
+ Inflecto.underscore('DataMapper').should == 'data_mapper'
7
+ end
8
+
9
+ it 'underscores Merb as merb' do
10
+ Inflecto.underscore('Merb').should == 'merb'
11
+ end
12
+
13
+ it 'underscores DataMapper::Resource as data_mapper/resource' do
14
+ Inflecto.underscore('DataMapper::Resource').should == 'data_mapper/resource'
15
+ end
16
+
17
+ it 'underscores Merb::BootLoader::Rackup as merb/boot_loader/rackup' do
18
+ Inflecto.underscore('Merb::BootLoader::Rackup').should == 'merb/boot_loader/rackup'
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inflecto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - The rails, merb & datamapper team
9
+ - Markus Schirp
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-22 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Inflector for strings
16
+ email:
17
+ - mbj@seonic.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - LICENSE
22
+ - README.md
23
+ - TODO
24
+ files:
25
+ - .gitignore
26
+ - .rspec
27
+ - .travis.yml
28
+ - Changelog.md
29
+ - Gemfile
30
+ - Gemfile.devtools
31
+ - Guardfile
32
+ - LICENSE
33
+ - README.md
34
+ - Rakefile
35
+ - TODO
36
+ - config/flay.yml
37
+ - config/flog.yml
38
+ - config/mutant.yml
39
+ - config/roodi.yml
40
+ - config/site.reek
41
+ - config/yardstick.yml
42
+ - inflecto.gemspec
43
+ - lib/inflecto.rb
44
+ - lib/inflecto/defaults.rb
45
+ - lib/inflecto/inflections.rb
46
+ - spec/integration/inflector_spec.rb
47
+ - spec/rcov.opts
48
+ - spec/shared/command_method_behavior.rb
49
+ - spec/shared/each_method_behaviour.rb
50
+ - spec/shared/hash_method_behavior.rb
51
+ - spec/shared/idempotent_method_behavior.rb
52
+ - spec/shared/invertible_method_behaviour.rb
53
+ - spec/shared/mutator_behavior.rb
54
+ - spec/spec_helper.rb
55
+ - spec/unit/inflector/class_methods/camelize_spec.rb
56
+ - spec/unit/inflector/class_methods/classify_spec.rb
57
+ - spec/unit/inflector/class_methods/demodulize_spec.rb
58
+ - spec/unit/inflector/class_methods/foreign_key_spec.rb
59
+ - spec/unit/inflector/class_methods/humanize_spec.rb
60
+ - spec/unit/inflector/class_methods/pluralize_spec.rb
61
+ - spec/unit/inflector/class_methods/singularize_spec.rb
62
+ - spec/unit/inflector/class_methods/tabelize_spec.rb
63
+ - spec/unit/inflector/class_methods/underscore_spec.rb
64
+ homepage: https://github.com/mbj/inflecto
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Inflector for strings
88
+ test_files:
89
+ - spec/integration/inflector_spec.rb
90
+ - spec/unit/inflector/class_methods/camelize_spec.rb
91
+ - spec/unit/inflector/class_methods/classify_spec.rb
92
+ - spec/unit/inflector/class_methods/demodulize_spec.rb
93
+ - spec/unit/inflector/class_methods/foreign_key_spec.rb
94
+ - spec/unit/inflector/class_methods/humanize_spec.rb
95
+ - spec/unit/inflector/class_methods/pluralize_spec.rb
96
+ - spec/unit/inflector/class_methods/singularize_spec.rb
97
+ - spec/unit/inflector/class_methods/tabelize_spec.rb
98
+ - spec/unit/inflector/class_methods/underscore_spec.rb
99
+ has_rdoc: