sleeping_king_studios-tools 0.7.0 → 1.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 +5 -5
- data/CHANGELOG.md +54 -3
- data/CODE_OF_CONDUCT.md +132 -0
- data/DEVELOPMENT.md +7 -16
- data/LICENSE +1 -1
- data/README.md +71 -145
- data/lib/sleeping_king_studios/tools.rb +12 -6
- data/lib/sleeping_king_studios/tools/array_tools.rb +86 -58
- data/lib/sleeping_king_studios/tools/base.rb +20 -0
- data/lib/sleeping_king_studios/tools/core_tools.rb +78 -19
- data/lib/sleeping_king_studios/tools/hash_tools.rb +69 -42
- data/lib/sleeping_king_studios/tools/integer_tools.rb +97 -55
- data/lib/sleeping_king_studios/tools/object_tools.rb +75 -52
- data/lib/sleeping_king_studios/tools/string_tools.rb +69 -96
- data/lib/sleeping_king_studios/tools/toolbelt.rb +44 -23
- data/lib/sleeping_king_studios/tools/toolbox.rb +2 -2
- data/lib/sleeping_king_studios/tools/toolbox/constant_map.rb +75 -74
- data/lib/sleeping_king_studios/tools/toolbox/inflector.rb +124 -0
- data/lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb +173 -0
- data/lib/sleeping_king_studios/tools/toolbox/mixin.rb +11 -11
- data/lib/sleeping_king_studios/tools/toolbox/semantic_version.rb +15 -14
- data/lib/sleeping_king_studios/tools/version.rb +14 -10
- metadata +106 -35
- data/lib/sleeping_king_studios/tools/all.rb +0 -5
- data/lib/sleeping_king_studios/tools/enumerable_tools.rb +0 -8
- data/lib/sleeping_king_studios/tools/semantic_version.rb +0 -15
- data/lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb +0 -185
- data/lib/sleeping_king_studios/tools/toolbox/configuration.rb +0 -207
- data/lib/sleeping_king_studios/tools/toolbox/delegator.rb +0 -175
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sleeping_king_studios/tools/toolbox'
|
4
4
|
|
@@ -6,27 +6,27 @@ module SleepingKingStudios::Tools::Toolbox
|
|
6
6
|
# Implements recursive inheritance of both class and instance methods.
|
7
7
|
module Mixin
|
8
8
|
# @api private
|
9
|
-
def self.mixin?
|
9
|
+
def self.mixin?(mod)
|
10
10
|
return false unless mod.is_a?(Module)
|
11
11
|
|
12
12
|
mod.singleton_class.include?(self)
|
13
|
-
end
|
13
|
+
end
|
14
14
|
|
15
|
-
# @
|
16
|
-
def included
|
15
|
+
# @private
|
16
|
+
def included(other)
|
17
17
|
return super unless defined?(self::ClassMethods)
|
18
18
|
|
19
19
|
if SleepingKingStudios::Tools::Toolbox::Mixin.mixin?(other)
|
20
20
|
unless other.constants(false).include?(:ClassMethods)
|
21
21
|
other.const_set(:ClassMethods, Module.new)
|
22
|
-
end
|
22
|
+
end
|
23
23
|
|
24
|
-
other::ClassMethods.
|
24
|
+
other::ClassMethods.include(self::ClassMethods)
|
25
25
|
else
|
26
26
|
other.extend self::ClassMethods
|
27
|
-
end
|
27
|
+
end
|
28
28
|
|
29
29
|
super
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sleeping_king_studios/tools/toolbox'
|
4
4
|
|
@@ -47,7 +47,7 @@ module SleepingKingStudios::Tools::Toolbox
|
|
47
47
|
#
|
48
48
|
# @raise InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.
|
49
49
|
def to_gem_version
|
50
|
-
str = "#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
|
50
|
+
str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
|
51
51
|
|
52
52
|
prerelease = const_fetch(:PRERELEASE, nil)
|
53
53
|
str << ".#{prerelease}" unless prerelease.nil? || prerelease.empty?
|
@@ -56,7 +56,7 @@ module SleepingKingStudios::Tools::Toolbox
|
|
56
56
|
str << ".#{build}" unless build.nil? || build.empty?
|
57
57
|
|
58
58
|
str
|
59
|
-
end
|
59
|
+
end
|
60
60
|
|
61
61
|
# Concatenates the MAJOR, MINOR, and PATCH constant values with PRERELEASE
|
62
62
|
# and BUILD (if available) to generate a semantic version string. The
|
@@ -82,7 +82,7 @@ module SleepingKingStudios::Tools::Toolbox
|
|
82
82
|
#
|
83
83
|
# @raise InvalidVersionError If MAJOR, MINOR, or PATCH is undefined.
|
84
84
|
def to_version
|
85
|
-
str = "#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
|
85
|
+
str = +"#{const_fetch :MAJOR}.#{const_fetch :MINOR}.#{const_fetch :PATCH}"
|
86
86
|
|
87
87
|
prerelease = const_fetch(:PRERELEASE, nil)
|
88
88
|
str << "-#{prerelease}" unless prerelease.nil? || prerelease.empty?
|
@@ -91,18 +91,19 @@ module SleepingKingStudios::Tools::Toolbox
|
|
91
91
|
str << "+#{build}" unless build.nil? || build.empty?
|
92
92
|
|
93
93
|
str
|
94
|
-
end
|
94
|
+
end
|
95
95
|
|
96
96
|
private
|
97
97
|
|
98
98
|
FETCH_DEFAULT = Object.new.freeze
|
99
99
|
|
100
|
-
def const_fetch
|
101
|
-
if
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
100
|
+
def const_fetch(name, default = FETCH_DEFAULT)
|
101
|
+
return const_get(name).to_s if const_defined?(name)
|
102
|
+
|
103
|
+
return nil unless default == FETCH_DEFAULT
|
104
|
+
|
105
|
+
raise InvalidVersionError,
|
106
|
+
"undefined constant for #{name.downcase} version"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sleeping_king_studios/tools/toolbox/semantic_version'
|
4
4
|
|
@@ -10,15 +10,19 @@ module SleepingKingStudios
|
|
10
10
|
module Version
|
11
11
|
extend SleepingKingStudios::Tools::Toolbox::SemanticVersion
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
MINOR
|
17
|
-
|
13
|
+
# Major version.
|
14
|
+
MAJOR = 1
|
15
|
+
# Minor version.
|
16
|
+
MINOR = 0
|
17
|
+
# Patch version.
|
18
|
+
PATCH = 2
|
19
|
+
# Prerelease version.
|
18
20
|
PRERELEASE = nil
|
19
|
-
|
20
|
-
|
21
|
+
# Build metadata.
|
22
|
+
BUILD = nil
|
23
|
+
end
|
21
24
|
|
25
|
+
# The current version of the gem.
|
22
26
|
VERSION = Version.to_gem_version
|
23
|
-
end
|
24
|
-
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,73 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleeping_king_studios-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob "Merlin" Smith
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '13.0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '13.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
47
|
+
version: '3.10'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
54
|
+
version: '3.10'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 8.2.2
|
61
|
+
version: '1.6'
|
51
62
|
type: :development
|
52
63
|
prerelease: false
|
53
64
|
version_requirements: !ruby/object:Gem::Requirement
|
54
65
|
requirements:
|
55
66
|
- - "~>"
|
56
67
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
58
|
-
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
59
81
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
82
|
+
version: '0.5'
|
61
83
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: rspec
|
84
|
+
name: rubocop-rspec
|
63
85
|
requirement: !ruby/object:Gem::Requirement
|
64
86
|
requirements:
|
65
87
|
- - "~>"
|
66
88
|
- !ruby/object:Gem::Version
|
67
89
|
version: '2.1'
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 2.1.1
|
71
90
|
type: :development
|
72
91
|
prerelease: false
|
73
92
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -75,12 +94,65 @@ dependencies:
|
|
75
94
|
- - "~>"
|
76
95
|
- !ruby/object:Gem::Version
|
77
96
|
version: '2.1'
|
78
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.18.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
79
109
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
110
|
+
version: 0.18.5
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-sleeping_king_studios
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.5'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.5'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sleeping_king_studios-tasks
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.4'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.4'
|
81
153
|
description: |
|
82
|
-
A library of utility services and concerns to expand the functionality of
|
83
|
-
classes without polluting the global namespace.
|
154
|
+
A library of utility services and concerns to expand the functionality of
|
155
|
+
core classes without polluting the global namespace.
|
84
156
|
email:
|
85
157
|
- merlin@sleepingkingstudios.com
|
86
158
|
executables: []
|
@@ -88,33 +160,33 @@ extensions: []
|
|
88
160
|
extra_rdoc_files: []
|
89
161
|
files:
|
90
162
|
- CHANGELOG.md
|
163
|
+
- CODE_OF_CONDUCT.md
|
91
164
|
- DEVELOPMENT.md
|
92
165
|
- LICENSE
|
93
166
|
- README.md
|
94
167
|
- lib/sleeping_king_studios/tools.rb
|
95
|
-
- lib/sleeping_king_studios/tools/all.rb
|
96
168
|
- lib/sleeping_king_studios/tools/array_tools.rb
|
169
|
+
- lib/sleeping_king_studios/tools/base.rb
|
97
170
|
- lib/sleeping_king_studios/tools/core_tools.rb
|
98
|
-
- lib/sleeping_king_studios/tools/enumerable_tools.rb
|
99
171
|
- lib/sleeping_king_studios/tools/hash_tools.rb
|
100
172
|
- lib/sleeping_king_studios/tools/integer_tools.rb
|
101
173
|
- lib/sleeping_king_studios/tools/object_tools.rb
|
102
|
-
- lib/sleeping_king_studios/tools/semantic_version.rb
|
103
174
|
- lib/sleeping_king_studios/tools/string_tools.rb
|
104
|
-
- lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb
|
105
175
|
- lib/sleeping_king_studios/tools/toolbelt.rb
|
106
176
|
- lib/sleeping_king_studios/tools/toolbox.rb
|
107
|
-
- lib/sleeping_king_studios/tools/toolbox/configuration.rb
|
108
177
|
- lib/sleeping_king_studios/tools/toolbox/constant_map.rb
|
109
|
-
- lib/sleeping_king_studios/tools/toolbox/
|
178
|
+
- lib/sleeping_king_studios/tools/toolbox/inflector.rb
|
179
|
+
- lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb
|
110
180
|
- lib/sleeping_king_studios/tools/toolbox/mixin.rb
|
111
181
|
- lib/sleeping_king_studios/tools/toolbox/semantic_version.rb
|
112
182
|
- lib/sleeping_king_studios/tools/version.rb
|
113
183
|
homepage: http://sleepingkingstudios.com
|
114
184
|
licenses:
|
115
185
|
- MIT
|
116
|
-
metadata:
|
117
|
-
|
186
|
+
metadata:
|
187
|
+
bug_tracker_uri: https://github.com/sleepingkingstudios/sleeping_king_studios-tools/issues
|
188
|
+
source_code_uri: https://github.com/sleepingkingstudios/sleeping_king_studios-tools
|
189
|
+
post_install_message:
|
118
190
|
rdoc_options: []
|
119
191
|
require_paths:
|
120
192
|
- lib
|
@@ -122,16 +194,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
194
|
requirements:
|
123
195
|
- - ">="
|
124
196
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
197
|
+
version: 2.5.0
|
126
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
199
|
requirements:
|
128
200
|
- - ">="
|
129
201
|
- !ruby/object:Gem::Version
|
130
202
|
version: '0'
|
131
203
|
requirements: []
|
132
|
-
|
133
|
-
|
134
|
-
signing_key:
|
204
|
+
rubygems_version: 3.2.3
|
205
|
+
signing_key:
|
135
206
|
specification_version: 4
|
136
207
|
summary: A library of utility services and concerns.
|
137
208
|
test_files: []
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# lib/sleeping_king_studios/tools/semantic_version.rb
|
2
|
-
|
3
|
-
require 'sleeping_king_studios/tools/core_tools'
|
4
|
-
|
5
|
-
SleepingKingStudios::Tools::CoreTools.deprecate(
|
6
|
-
'SleepingKingStudios::Tools::SemanticVersion',
|
7
|
-
:message => 'Use SleepingKingStudios::Tools::Toolbox::SemanticVersion instead.'
|
8
|
-
) # end deprecate
|
9
|
-
|
10
|
-
require 'sleeping_king_studios/tools/toolbox/semantic_version'
|
11
|
-
|
12
|
-
module SleepingKingStudios::Tools
|
13
|
-
# (see SleepingKingStudios::Tools::Toolbox::SemanticVersion)
|
14
|
-
SemanticVersion = Toolbox::SemanticVersion
|
15
|
-
end # module
|
@@ -1,185 +0,0 @@
|
|
1
|
-
# lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb
|
2
|
-
|
3
|
-
require 'sleeping_king_studios/tools/string_tools'
|
4
|
-
|
5
|
-
module SleepingKingStudios::Tools::StringTools
|
6
|
-
# Inflector class to handle word pluralization using a set of defined rules
|
7
|
-
# and irregular/uncountable words.
|
8
|
-
class PluralInflector
|
9
|
-
# Defines an irregular word, which is a singular and plural word pair that
|
10
|
-
# do not obey any defined rule, such as "goose" and "geese".
|
11
|
-
#
|
12
|
-
# @param singular [String] The singular form of the word.
|
13
|
-
# @param plural [String] The plural form of the word.
|
14
|
-
def define_irregular_word singular, plural
|
15
|
-
irregular_words[singular] = plural
|
16
|
-
inverse_irregular_words[plural] = singular
|
17
|
-
end # method define_irregular_word
|
18
|
-
|
19
|
-
# Defines a rule for pluralization. The rule will be applied to any words
|
20
|
-
# that match the first parameter, performing a replace on the word using
|
21
|
-
# the second parameter.
|
22
|
-
#
|
23
|
-
# Rules are applied in reverse order of definition, meaning that rules
|
24
|
-
# defined later will take precedence over previously defined rules.
|
25
|
-
#
|
26
|
-
# @param match [Regexp] The matching rule.
|
27
|
-
# @param replace [String] The replacement string.
|
28
|
-
def define_plural_rule match, replace
|
29
|
-
plural_rules.unshift [match, replace]
|
30
|
-
end # method define_plural_rule
|
31
|
-
|
32
|
-
# Defines a rule for singularization. The rule will be applied to any words
|
33
|
-
# that match the first parameter, performing a replace on the word using
|
34
|
-
# the second parameter.
|
35
|
-
#
|
36
|
-
# Rules are applied in reverse order of definition, meaning that rules
|
37
|
-
# defined later will take precedence over previously defined rules.
|
38
|
-
#
|
39
|
-
# @param match [Regexp] The matching rule.
|
40
|
-
# @param replace [String] The replacement string.
|
41
|
-
def define_singular_rule match, replace
|
42
|
-
singular_rules.unshift [match, replace]
|
43
|
-
end # method define_singular_rule
|
44
|
-
|
45
|
-
# Defines an uncountable word, such as "data". If #pluralize or #singularize
|
46
|
-
# is called with an uncountable word as its parameter, it will return the
|
47
|
-
# unmodified word.
|
48
|
-
#
|
49
|
-
# @param word [String] The uncountable word.
|
50
|
-
def define_uncountable_word word
|
51
|
-
uncountable_words << word
|
52
|
-
end # method define_uncountable_word
|
53
|
-
|
54
|
-
# Takes a word in singular form and returns the plural form, based on the
|
55
|
-
# defined rules and known irregular/uncountable words.
|
56
|
-
#
|
57
|
-
# First, checks if the word is known to be uncountable (see
|
58
|
-
# #define_uncountable_word). Then, checks if the word is known to be
|
59
|
-
# irregular (see #define_irregular_word). Finally, iterates through the
|
60
|
-
# defined plural rules from most recently defined to first defined (see
|
61
|
-
# #define_plural_rule).
|
62
|
-
#
|
63
|
-
# @note The defined rules and exceptions are deliberately basic. Each
|
64
|
-
# application is responsible for defining its own pluralization rules
|
65
|
-
# using this framework.
|
66
|
-
#
|
67
|
-
# @param str [String] The word to pluralize.
|
68
|
-
#
|
69
|
-
# @return [String] The pluralized word.
|
70
|
-
#
|
71
|
-
# @see #singularize
|
72
|
-
def pluralize str
|
73
|
-
str = str.to_s.strip
|
74
|
-
normalized = str.downcase
|
75
|
-
|
76
|
-
uncountable_words.each do |word|
|
77
|
-
return str if word == normalized
|
78
|
-
end # each
|
79
|
-
|
80
|
-
return str if inverse_irregular_words.key?(normalized)
|
81
|
-
|
82
|
-
return irregular_words[normalized] if irregular_words.key?(normalized)
|
83
|
-
|
84
|
-
plural_rules.each do |match, replace|
|
85
|
-
next unless str =~ match
|
86
|
-
|
87
|
-
return str.sub(match, replace)
|
88
|
-
end # each
|
89
|
-
|
90
|
-
str
|
91
|
-
end # method pluralize
|
92
|
-
|
93
|
-
# Takes a word in plural form and returns the singular form, based on the
|
94
|
-
# defined rules and known irregular/uncountable words.
|
95
|
-
#
|
96
|
-
# @param str [String] The word to singularize.
|
97
|
-
#
|
98
|
-
# @return [String] The singularized word.
|
99
|
-
#
|
100
|
-
# @see #pluralize
|
101
|
-
def singularize str
|
102
|
-
str = str.to_s.strip
|
103
|
-
normalized = str.downcase
|
104
|
-
|
105
|
-
uncountable_words.each do |word|
|
106
|
-
return str if word == normalized
|
107
|
-
end # each
|
108
|
-
|
109
|
-
return inverse_irregular_words[normalized] if inverse_irregular_words.key?(normalized)
|
110
|
-
|
111
|
-
singular_rules.each do |match, replace|
|
112
|
-
next unless str =~ match
|
113
|
-
|
114
|
-
return str.sub(match, replace)
|
115
|
-
end # each
|
116
|
-
|
117
|
-
str
|
118
|
-
end # method singularize
|
119
|
-
|
120
|
-
private
|
121
|
-
|
122
|
-
def define_irregular_words
|
123
|
-
define_irregular_word 'child', 'children'
|
124
|
-
define_irregular_word 'person', 'people'
|
125
|
-
end # method define_irregular_words
|
126
|
-
|
127
|
-
def inverse_irregular_words
|
128
|
-
return @inverse_irregular_words if @inverse_irregular_words
|
129
|
-
|
130
|
-
@inverse_irregular_words = {}
|
131
|
-
|
132
|
-
define_irregular_words
|
133
|
-
|
134
|
-
@inverse_irregular_words
|
135
|
-
end # method inverse_irregular_words
|
136
|
-
|
137
|
-
def irregular_words
|
138
|
-
return @irregular_words if @irregular_words
|
139
|
-
|
140
|
-
@irregular_words = {}
|
141
|
-
|
142
|
-
define_irregular_words
|
143
|
-
|
144
|
-
@irregular_words
|
145
|
-
end # method irregular_words
|
146
|
-
|
147
|
-
def plural_rules
|
148
|
-
return @plural_rules if @plural_rules
|
149
|
-
|
150
|
-
@plural_rules = []
|
151
|
-
|
152
|
-
define_plural_rule(/$/, 's')
|
153
|
-
define_plural_rule(/s$/, 's')
|
154
|
-
define_plural_rule(/(ss|[xz]|[cs]h)$/i, '\1es')
|
155
|
-
define_plural_rule(/([^aeiouy]o)$/i, '\1es')
|
156
|
-
define_plural_rule(/([^aeiouy])y$/i, '\1ies')
|
157
|
-
|
158
|
-
@plural_rules
|
159
|
-
end # method plural_rules
|
160
|
-
|
161
|
-
def singular_rules
|
162
|
-
return @singular_rules if @singular_rules
|
163
|
-
|
164
|
-
@singular_rules = []
|
165
|
-
|
166
|
-
define_singular_rule(/s$/i, '')
|
167
|
-
define_singular_rule(/ss$/i, 'ss')
|
168
|
-
define_singular_rule(/(ss|[sxz]|[cs]h)es$/, '\1')
|
169
|
-
define_singular_rule(/([^aeiouy]o)es$/, '\1')
|
170
|
-
define_singular_rule(/([^aeiouy])ies$/i, '\1y')
|
171
|
-
|
172
|
-
@singular_rules
|
173
|
-
end # method singular_rules
|
174
|
-
|
175
|
-
def uncountable_words
|
176
|
-
return @uncountable_words if @uncountable_words
|
177
|
-
|
178
|
-
@uncountable_words = []
|
179
|
-
|
180
|
-
@uncountable_words << 'data'
|
181
|
-
|
182
|
-
@uncountable_words
|
183
|
-
end # method uncountable_words
|
184
|
-
end # class
|
185
|
-
end # module
|