sleeping_king_studios-tools 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +32 -3
  3. data/DEVELOPMENT.md +5 -7
  4. data/README.md +3 -64
  5. data/lib/sleeping_king_studios/tools.rb +12 -6
  6. data/lib/sleeping_king_studios/tools/all.rb +8 -3
  7. data/lib/sleeping_king_studios/tools/array_tools.rb +83 -58
  8. data/lib/sleeping_king_studios/tools/base.rb +18 -0
  9. data/lib/sleeping_king_studios/tools/core_tools.rb +68 -22
  10. data/lib/sleeping_king_studios/tools/enumerable_tools.rb +6 -3
  11. data/lib/sleeping_king_studios/tools/hash_tools.rb +59 -47
  12. data/lib/sleeping_king_studios/tools/integer_tools.rb +97 -55
  13. data/lib/sleeping_king_studios/tools/object_tools.rb +67 -50
  14. data/lib/sleeping_king_studios/tools/string_tools.rb +81 -63
  15. data/lib/sleeping_king_studios/tools/toolbelt.rb +46 -22
  16. data/lib/sleeping_king_studios/tools/toolbox.rb +2 -2
  17. data/lib/sleeping_king_studios/tools/toolbox/configuration.rb +197 -122
  18. data/lib/sleeping_king_studios/tools/toolbox/constant_map.rb +24 -51
  19. data/lib/sleeping_king_studios/tools/toolbox/delegator.rb +50 -29
  20. data/lib/sleeping_king_studios/tools/toolbox/inflector.rb +130 -0
  21. data/lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb +171 -0
  22. data/lib/sleeping_king_studios/tools/toolbox/mixin.rb +10 -10
  23. data/lib/sleeping_king_studios/tools/toolbox/semantic_version.rb +15 -14
  24. data/lib/sleeping_king_studios/tools/version.rb +6 -8
  25. metadata +84 -26
  26. data/lib/sleeping_king_studios/tools/semantic_version.rb +0 -15
  27. data/lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb +0 -185
@@ -1,4 +1,4 @@
1
- # lib/sleeping_king_studios/tools/toolbox/mixin.rb
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? mod
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 # class method mixin?
13
+ end
14
14
 
15
15
  # @api private
16
- def included other
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 # unless
22
+ end
23
23
 
24
- other::ClassMethods.send :include, self::ClassMethods
24
+ other::ClassMethods.include(self::ClassMethods)
25
25
  else
26
26
  other.extend self::ClassMethods
27
- end # if-else
27
+ end
28
28
 
29
29
  super
30
- end # method included
31
- end # module
32
- end # module
30
+ end
31
+ end
32
+ end
@@ -1,4 +1,4 @@
1
- # lib/sleeping_king_studios/tools/toolbox/semantic_version.rb
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 # method to_version
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 # method to_version
94
+ end
95
95
 
96
96
  private
97
97
 
98
98
  FETCH_DEFAULT = Object.new.freeze
99
99
 
100
- def const_fetch name, default = FETCH_DEFAULT
101
- if self.const_defined?(name)
102
- return self.const_get(name).to_s
103
- elsif default == FETCH_DEFAULT
104
- raise InvalidVersionError.new "undefined constant for #{name.downcase} version"
105
- end # if-else
106
- end # method const_fetch
107
- end # module
108
- end # module
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
- # lib/sleeping_king_studios/tools/version.rb
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'sleeping_king_studios/tools/toolbox/semantic_version'
4
4
 
@@ -10,15 +10,13 @@ module SleepingKingStudios
10
10
  module Version
11
11
  extend SleepingKingStudios::Tools::Toolbox::SemanticVersion
12
12
 
13
- private
14
-
15
13
  MAJOR = 0
16
- MINOR = 7
17
- PATCH = 1
14
+ MINOR = 8
15
+ PATCH = 0
18
16
  PRERELEASE = nil
19
17
  BUILD = nil
20
- end # module
18
+ end
21
19
 
22
20
  VERSION = Version.to_gem_version
23
- end # module
24
- end # module
21
+ end
22
+ end
metadata CHANGED
@@ -1,86 +1,144 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeping_king_studios-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-23 00:00:00.000000000 Z
11
+ date: 2020-07-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: '12.0'
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: '12.0'
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.4'
47
+ version: '3.9'
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.4'
54
+ version: '3.9'
41
55
  - !ruby/object:Gem::Dependency
42
- name: byebug
56
+ name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '8.2'
48
- - - ">="
61
+ version: 0.87.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.87.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
49
74
  - !ruby/object:Gem::Version
50
- version: 8.2.2
75
+ version: 1.42.0
51
76
  type: :development
52
77
  prerelease: false
53
78
  version_requirements: !ruby/object:Gem::Requirement
54
79
  requirements:
55
80
  - - "~>"
56
81
  - !ruby/object:Gem::Version
57
- version: '8.2'
58
- - - ">="
82
+ version: 1.42.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
59
88
  - !ruby/object:Gem::Version
60
- version: 8.2.2
89
+ version: 0.18.5
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.18.5
61
97
  - !ruby/object:Gem::Dependency
62
- name: rspec-sleeping_king_studios
98
+ name: thor
63
99
  requirement: !ruby/object:Gem::Requirement
64
100
  requirements:
65
101
  - - "~>"
66
102
  - !ruby/object:Gem::Version
67
- version: '2.1'
68
- - - ">="
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
69
109
  - !ruby/object:Gem::Version
70
- version: 2.1.1
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-sleeping_king_studios
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.5'
71
118
  type: :development
72
119
  prerelease: false
73
120
  version_requirements: !ruby/object:Gem::Requirement
74
121
  requirements:
75
122
  - - "~>"
76
123
  - !ruby/object:Gem::Version
77
- version: '2.1'
78
- - - ">="
124
+ version: '2.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sleeping_king_studios-tasks
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
79
137
  - !ruby/object:Gem::Version
80
- version: 2.1.1
138
+ version: '0.3'
81
139
  description: |
82
- A library of utility services and concerns to expand the functionality of core
83
- classes without polluting the global namespace.
140
+ A library of utility services and concerns to expand the functionality of
141
+ core classes without polluting the global namespace.
84
142
  email:
85
143
  - merlin@sleepingkingstudios.com
86
144
  executables: []
@@ -94,19 +152,20 @@ files:
94
152
  - lib/sleeping_king_studios/tools.rb
95
153
  - lib/sleeping_king_studios/tools/all.rb
96
154
  - lib/sleeping_king_studios/tools/array_tools.rb
155
+ - lib/sleeping_king_studios/tools/base.rb
97
156
  - lib/sleeping_king_studios/tools/core_tools.rb
98
157
  - lib/sleeping_king_studios/tools/enumerable_tools.rb
99
158
  - lib/sleeping_king_studios/tools/hash_tools.rb
100
159
  - lib/sleeping_king_studios/tools/integer_tools.rb
101
160
  - lib/sleeping_king_studios/tools/object_tools.rb
102
- - lib/sleeping_king_studios/tools/semantic_version.rb
103
161
  - lib/sleeping_king_studios/tools/string_tools.rb
104
- - lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb
105
162
  - lib/sleeping_king_studios/tools/toolbelt.rb
106
163
  - lib/sleeping_king_studios/tools/toolbox.rb
107
164
  - lib/sleeping_king_studios/tools/toolbox/configuration.rb
108
165
  - lib/sleeping_king_studios/tools/toolbox/constant_map.rb
109
166
  - lib/sleeping_king_studios/tools/toolbox/delegator.rb
167
+ - lib/sleeping_king_studios/tools/toolbox/inflector.rb
168
+ - lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb
110
169
  - lib/sleeping_king_studios/tools/toolbox/mixin.rb
111
170
  - lib/sleeping_king_studios/tools/toolbox/semantic_version.rb
112
171
  - lib/sleeping_king_studios/tools/version.rb
@@ -129,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
188
  - !ruby/object:Gem::Version
130
189
  version: '0'
131
190
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.6.11
191
+ rubygems_version: 3.1.2
134
192
  signing_key:
135
193
  specification_version: 4
136
194
  summary: A library of utility services and concerns.
@@ -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