lite-ruby 1.0.14 → 1.0.15

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.
@@ -1,632 +1,634 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- class String
4
-
5
- TRANSLITERATIONS ||= {
6
- 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'Ae',
7
- 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I',
8
- 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O',
9
- 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U',
10
- 'Ý' => 'Y', 'Þ' => 'Th', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a',
11
- 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e',
12
- 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n',
13
- 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u',
14
- 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y', 'Ā' => 'A',
15
- 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ć' => 'C', 'ć' => 'c',
16
- 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ď' => 'D',
17
- 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e',
18
- 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G',
19
- 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g',
20
- 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I',
21
- 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i',
22
- 'IJ' => 'Ij', 'ij' => 'ij', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'ĸ' => 'k',
23
- 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L',
24
- 'ŀ' => 'l', 'Ł' => 'L', 'ł' => 'l', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n',
25
- 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'n', 'Ŋ' => 'Ng', 'ŋ' => 'ng', 'Ō' => 'O', 'ō' => 'o',
26
- 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Œ' => 'OE', 'œ' => 'oe', 'Ŕ' => 'R',
27
- 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's',
28
- 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'Ţ' => 'T',
29
- 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ũ' => 'U', 'ũ' => 'u',
30
- 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U',
31
- 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ŷ' => 'Y', 'ŷ' => 'y',
32
- 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z'
33
- }.freeze
34
-
35
- def acronym
36
- dup.acronym!
37
- end
3
+ if Lite::Ruby.configuration.monkey_patches.include?('string')
4
+ class String
5
+
6
+ TRANSLITERATIONS ||= {
7
+ 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'Ae',
8
+ 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I',
9
+ 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O',
10
+ 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U',
11
+ 'Ý' => 'Y', 'Þ' => 'Th', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a',
12
+ 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e',
13
+ 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n',
14
+ 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u',
15
+ 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y', 'Ā' => 'A',
16
+ 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ć' => 'C', 'ć' => 'c',
17
+ 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ď' => 'D',
18
+ 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e',
19
+ 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G',
20
+ 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g',
21
+ 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I',
22
+ 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i',
23
+ 'IJ' => 'Ij', 'ij' => 'ij', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'ĸ' => 'k',
24
+ 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L',
25
+ 'ŀ' => 'l', 'Ł' => 'L', 'ł' => 'l', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n',
26
+ 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'n', 'Ŋ' => 'Ng', 'ŋ' => 'ng', 'Ō' => 'O', 'ō' => 'o',
27
+ 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Œ' => 'OE', 'œ' => 'oe', 'Ŕ' => 'R',
28
+ 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's',
29
+ 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'Ţ' => 'T',
30
+ 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ũ' => 'U', 'ũ' => 'u',
31
+ 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U',
32
+ 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ŷ' => 'Y', 'ŷ' => 'y',
33
+ 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z'
34
+ }.freeze
35
+
36
+ def acronym
37
+ dup.acronym!
38
+ end
38
39
 
39
- def acronym!
40
- gsub!(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./, '\\2') || self
41
- end
40
+ def acronym!
41
+ gsub!(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./, '\\2') || self
42
+ end
42
43
 
43
- def any?(*keys)
44
- keys.any? { |key| include?(key) }
45
- end
44
+ def any?(*keys)
45
+ keys.any? { |key| include?(key) }
46
+ end
46
47
 
47
- def ascii_only(alt = '')
48
- dup.ascii_only!(alt)
49
- end
48
+ def ascii_only(alt = '')
49
+ dup.ascii_only!(alt)
50
+ end
50
51
 
51
- def ascii_only!(alt = '')
52
- encode_only!('ASCII', alt)
53
- end
52
+ def ascii_only!(alt = '')
53
+ encode_only!('ASCII', alt)
54
+ end
54
55
 
55
- def at(position)
56
- self[position]
57
- end
56
+ def at(position)
57
+ self[position]
58
+ end
58
59
 
59
- def camelize(first_letter = :upper)
60
- case first_letter
61
- when :upper, true then modulize.gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase }
62
- when :lower, false then modulize.gsub(/(\A|\s)([A-Z])/) { $1 + $2.downcase }
63
- end || modulize
64
- end
60
+ def camelize(first_letter = :upper)
61
+ case first_letter
62
+ when :upper, true then modulize.gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase }
63
+ when :lower, false then modulize.gsub(/(\A|\s)([A-Z])/) { $1 + $2.downcase }
64
+ end || modulize
65
+ end
65
66
 
66
- alias camelcase camelize
67
+ alias camelcase camelize
67
68
 
68
- def camelize!(first_letter = :upper)
69
- replace(camelize(first_letter))
70
- end
69
+ def camelize!(first_letter = :upper)
70
+ replace(camelize(first_letter))
71
+ end
71
72
 
72
- alias camelcase! camelize!
73
+ alias camelcase! camelize!
73
74
 
74
- def capitalized?
75
- capitalize == self
76
- end
75
+ def capitalized?
76
+ capitalize == self
77
+ end
77
78
 
78
- def classify
79
- dup.classify!
80
- end
79
+ def classify
80
+ dup.classify!
81
+ end
81
82
 
82
- def classify!
83
- sub!(/.*\./, '')
84
- camelize!
85
- end
83
+ def classify!
84
+ sub!(/.*\./, '')
85
+ camelize!
86
+ end
86
87
 
87
- def constantize
88
- Object.const_get(camelize)
89
- end
88
+ def constantize
89
+ Object.const_get(camelize)
90
+ end
90
91
 
91
- def dasherize
92
- underscore.tr('_', '-')
93
- end
92
+ def dasherize
93
+ underscore.tr('_', '-')
94
+ end
94
95
 
95
- def dasherize!
96
- replace(dasherize)
97
- end
96
+ def dasherize!
97
+ replace(dasherize)
98
+ end
98
99
 
99
- def deconstantize
100
- [0, rindex('::') || 0]
101
- end
100
+ def deconstantize
101
+ [0, rindex('::') || 0]
102
+ end
102
103
 
103
- def deconstantize!
104
- replace(deconstantize)
105
- end
104
+ def deconstantize!
105
+ replace(deconstantize)
106
+ end
106
107
 
107
- def dedupe(pattern)
108
- dup.dedupe!(pattern)
109
- end
108
+ def dedupe(pattern)
109
+ dup.dedupe!(pattern)
110
+ end
110
111
 
111
- def dedupe!(pattern)
112
- pattern.each_char { |char| gsub!(/#{Regexp.escape(char)}{2,}/, char) }
113
- self
114
- end
112
+ def dedupe!(pattern)
113
+ pattern.each_char { |char| gsub!(/#{Regexp.escape(char)}{2,}/, char) }
114
+ self
115
+ end
115
116
 
116
- def demodulize
117
- gsub(/^.*::/, '')
118
- end
117
+ def demodulize
118
+ gsub(/^.*::/, '')
119
+ end
119
120
 
120
- def demodulize!
121
- replace(demodulize)
122
- end
121
+ def demodulize!
122
+ replace(demodulize)
123
+ end
123
124
 
124
- def domain
125
- return self unless self =~ %r{^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)}
125
+ def domain
126
+ return self unless self =~ %r{^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)}
126
127
 
127
- Regexp.last_match(1)
128
- end
128
+ Regexp.last_match(1)
129
+ end
129
130
 
130
- def downcase?
131
- downcase == self
132
- end
131
+ def downcase?
132
+ downcase == self
133
+ end
133
134
 
134
- def each_word(&block)
135
- words.each(&block)
136
- end
135
+ def each_word(&block)
136
+ words.each(&block)
137
+ end
137
138
 
138
- def encode_only(encoding, alt = '')
139
- dup.encode_only!(encoding, alt)
140
- end
139
+ def encode_only(encoding, alt = '')
140
+ dup.encode_only!(encoding, alt)
141
+ end
141
142
 
142
- def encode_only!(encoding, alt = '')
143
- encoding_options = {
144
- invalid: :replace,
145
- undef: :replace,
146
- replace: alt,
147
- UNIVERSAL_NEWLINE_DECORATOR: true
148
- }
143
+ def encode_only!(encoding, alt = '')
144
+ encoding_options = {
145
+ invalid: :replace,
146
+ undef: :replace,
147
+ replace: alt,
148
+ UNIVERSAL_NEWLINE_DECORATOR: true
149
+ }
149
150
 
150
- encode!(Encoding.find(encoding), encoding_options)
151
- end
151
+ encode!(Encoding.find(encoding), encoding_options)
152
+ end
152
153
 
153
- def ellipsize(ellipsize_at, options = {})
154
- return self if length <= ellipsize_at
154
+ def ellipsize(ellipsize_at, options = {})
155
+ return self if length <= ellipsize_at
155
156
 
156
- separator = options[:separator] || '...'
157
- offset = options[:offset] || 4
157
+ separator = options[:separator] || '...'
158
+ offset = options[:offset] || 4
158
159
 
159
- "#{self[0, offset]}#{separator}#{self[-offset, offset]}"
160
- end
160
+ "#{self[0, offset]}#{separator}#{self[-offset, offset]}"
161
+ end
161
162
 
162
- def first(limit = 1)
163
- if limit.zero?
164
- ''
165
- elsif limit >= length
166
- self
167
- else
168
- to(limit - 1)
163
+ def first(limit = 1)
164
+ if limit.zero?
165
+ ''
166
+ elsif limit >= length
167
+ self
168
+ else
169
+ to(limit - 1)
170
+ end
169
171
  end
170
- end
171
172
 
172
- def format(*args)
173
- super(self, *args.flatten)
174
- end
173
+ def format(*args)
174
+ super(self, *args.flatten)
175
+ end
175
176
 
176
- def from(position)
177
- self[position..-1]
178
- end
177
+ def from(position)
178
+ self[position..-1]
179
+ end
179
180
 
180
- def headerize
181
- squish.each_word(&:capitalize!).join(' ')
182
- end
181
+ def headerize
182
+ squish.each_word(&:capitalize!).join(' ')
183
+ end
183
184
 
184
- def headerize!
185
- replace(headerize)
186
- end
185
+ def headerize!
186
+ replace(headerize)
187
+ end
187
188
 
188
- def humanize(options = {})
189
- dup.humanize!(options)
190
- end
189
+ def humanize(options = {})
190
+ dup.humanize!(options)
191
+ end
191
192
 
192
- def humanize!(capitalize: true)
193
- underscore!
194
- gsub!(/_id\z/, '')
195
- tr!('_', ' ')
196
- squish!
197
- gsub!(/([a-z\d]*)/i, &:downcase)
198
- gsub!(/\A\w/) { |str| capitalize ? str.upcase : str } || self
199
- end
193
+ def humanize!(capitalize: true)
194
+ underscore!
195
+ gsub!(/_id\z/, '')
196
+ tr!('_', ' ')
197
+ squish!
198
+ gsub!(/([a-z\d]*)/i, &:downcase)
199
+ gsub!(/\A\w/) { |str| capitalize ? str.upcase : str } || self
200
+ end
200
201
 
201
- def indent(amount, seperator = ' ')
202
- dup.indent!(amount, seperator)
203
- end
202
+ def indent(amount, seperator = ' ')
203
+ dup.indent!(amount, seperator)
204
+ end
204
205
 
205
- def indent!(amount, seperator = ' ')
206
- if amount >= 0
207
- gsub!(/^/, seperator * amount)
208
- else
209
- gsub!(/^#{Regexp.escape(seperator)}{0,#{-amount}}/, '')
206
+ def indent!(amount, seperator = ' ')
207
+ if amount >= 0
208
+ gsub!(/^/, seperator * amount)
209
+ else
210
+ gsub!(/^#{Regexp.escape(seperator)}{0,#{-amount}}/, '')
211
+ end
210
212
  end
211
- end
212
213
 
213
- def index_all(pattern)
214
- pattern = pattern.to_s if pattern.is_a?(Numeric)
215
- arr_indexes = []
216
- srch_index = rindex(pattern)
214
+ def index_all(pattern)
215
+ pattern = pattern.to_s if pattern.is_a?(Numeric)
216
+ arr_indexes = []
217
+ srch_index = rindex(pattern)
217
218
 
218
- while srch_index
219
- temp_string = self[0..(srch_index - 1)]
220
- arr_indexes << srch_index
221
- srch_index = srch_index.zero? ? nil : temp_string.rindex(pattern)
219
+ while srch_index
220
+ temp_string = self[0..(srch_index - 1)]
221
+ arr_indexes << srch_index
222
+ srch_index = srch_index.zero? ? nil : temp_string.rindex(pattern)
223
+ end
224
+
225
+ arr_indexes.reverse
222
226
  end
223
227
 
224
- arr_indexes.reverse
225
- end
228
+ def labelize(options = {})
229
+ dup.labelize!(options)
230
+ end
226
231
 
227
- def labelize(options = {})
228
- dup.labelize!(options)
229
- end
232
+ alias labelcase labelize
230
233
 
231
- alias labelcase labelize
234
+ def labelize!(capitalize: true)
235
+ underscore!
236
+ tr!('_', ' ')
237
+ squish!
238
+ gsub!(/([a-z\d]*)/i, &:downcase)
239
+ gsub!(/\A\w/) { |str| capitalize ? str.upcase : str }
240
+ gsub!(/ id\z/, ' ID') || self
241
+ end
232
242
 
233
- def labelize!(capitalize: true)
234
- underscore!
235
- tr!('_', ' ')
236
- squish!
237
- gsub!(/([a-z\d]*)/i, &:downcase)
238
- gsub!(/\A\w/) { |str| capitalize ? str.upcase : str }
239
- gsub!(/ id\z/, ' ID') || self
240
- end
243
+ alias labelcase! labelize!
241
244
 
242
- alias labelcase! labelize!
245
+ def last(limit = 1)
246
+ if limit.zero?
247
+ ''
248
+ elsif limit >= length
249
+ self
250
+ else
251
+ from(-limit)
252
+ end
253
+ end
243
254
 
244
- def last(limit = 1)
245
- if limit.zero?
246
- ''
247
- elsif limit >= length
248
- self
249
- else
250
- from(-limit)
255
+ def lchomp(match)
256
+ dup.lchomp!(match)
251
257
  end
252
- end
253
258
 
254
- def lchomp(match)
255
- dup.lchomp!(match)
256
- end
259
+ def lchomp!(match)
260
+ return self unless index(match)
257
261
 
258
- def lchomp!(match)
259
- return self unless index(match)
262
+ self[0...match.size] = ''
263
+ self
264
+ end
260
265
 
261
- self[0...match.size] = ''
262
- self
263
- end
266
+ def methodize
267
+ dup.methodize!
268
+ end
264
269
 
265
- def methodize
266
- dup.methodize!
267
- end
270
+ def methodize!
271
+ gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
272
+ gsub!(/([a-z])([A-Z])/, '\1_\2')
273
+ gsub!('/', '__')
274
+ gsub!('::', '__')
275
+ downcase! || self
276
+ end
268
277
 
269
- def methodize!
270
- gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
271
- gsub!(/([a-z])([A-Z])/, '\1_\2')
272
- gsub!('/', '__')
273
- gsub!('::', '__')
274
- downcase! || self
275
- end
278
+ def modulize
279
+ dup.modulize!
280
+ end
276
281
 
277
- def modulize
278
- dup.modulize!
279
- end
282
+ def modulize!
283
+ gsub!(/__(.?)/) { "::#{$1.upcase}" }
284
+ gsub!(%r{/(.?)}) { "::#{$1.upcase}" }
285
+ gsub!(/(?:_+|-+)([a-z])/) { $1.upcase }
286
+ gsub!(/(\A|\s)([a-z])/) { $1 + $2.upcase } || self
287
+ end
280
288
 
281
- def modulize!
282
- gsub!(/__(.?)/) { "::#{$1.upcase}" }
283
- gsub!(%r{/(.?)}) { "::#{$1.upcase}" }
284
- gsub!(/(?:_+|-+)([a-z])/) { $1.upcase }
285
- gsub!(/(\A|\s)([a-z])/) { $1 + $2.upcase } || self
286
- end
289
+ def mixedcase?
290
+ !upcase? && !downcase?
291
+ end
287
292
 
288
- def mixedcase?
289
- !upcase? && !downcase?
290
- end
293
+ def ordinal
294
+ to_i.ordinal
295
+ end
291
296
 
292
- def ordinal
293
- to_i.ordinal
294
- end
297
+ def ordinalize
298
+ to_i.ordinalize
299
+ end
295
300
 
296
- def ordinalize
297
- to_i.ordinalize
298
- end
301
+ def parameterize(separator: '-')
302
+ dup.parameterize!(separator: separator)
303
+ end
299
304
 
300
- def parameterize(separator: '-')
301
- dup.parameterize!(separator: separator)
302
- end
305
+ def parameterize!(separator: '-')
306
+ underscore!
307
+ gsub!(/\s+/, separator)
308
+ downcase! || self
309
+ end
303
310
 
304
- def parameterize!(separator: '-')
305
- underscore!
306
- gsub!(/\s+/, separator)
307
- downcase! || self
308
- end
311
+ def pathize
312
+ dup.pathize!
313
+ end
309
314
 
310
- def pathize
311
- dup.pathize!
312
- end
315
+ def pathize!
316
+ gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
317
+ gsub!(/([a-z])([A-Z])/, '\1_\2')
318
+ gsub!('__', '/')
319
+ gsub!('::', '/')
320
+ gsub!(/\s+/, '')
321
+ gsub!(/[?%*:|"<>.]+/, '')
322
+ downcase! || self
323
+ end
313
324
 
314
- def pathize!
315
- gsub!(/([A-Z]+)([A-Z])/, '\1_\2')
316
- gsub!(/([a-z])([A-Z])/, '\1_\2')
317
- gsub!('__', '/')
318
- gsub!('::', '/')
319
- gsub!(/\s+/, '')
320
- gsub!(/[?%*:|"<>.]+/, '')
321
- downcase! || self
322
- end
325
+ def pollute(delimiter = '^--^--^')
326
+ chars.map { |chr| "#{chr}#{delimiter}" }.join
327
+ end
323
328
 
324
- def pollute(delimiter = '^--^--^')
325
- chars.map { |chr| "#{chr}#{delimiter}" }.join
326
- end
329
+ def pollute!(delimiter = '^--^--^')
330
+ replace(pollute(delimiter))
331
+ end
327
332
 
328
- def pollute!(delimiter = '^--^--^')
329
- replace(pollute(delimiter))
330
- end
333
+ def pop
334
+ self[-1]
335
+ end
331
336
 
332
- def pop
333
- self[-1]
334
- end
337
+ def non_possessive
338
+ dup.non_possessive!
339
+ end
335
340
 
336
- def non_possessive
337
- dup.non_possessive!
338
- end
341
+ def non_possessive!
342
+ return self unless possessive?
339
343
 
340
- def non_possessive!
341
- return self unless possessive?
344
+ chomp!("'s") || chomp!("'") || self
345
+ end
342
346
 
343
- chomp!("'s") || chomp!("'") || self
344
- end
347
+ def possessive
348
+ return self if possessive?
345
349
 
346
- def possessive
347
- return self if possessive?
350
+ possession = end_with?('s') ? "'" : "'s"
351
+ "#{self}#{possession}"
352
+ end
348
353
 
349
- possession = end_with?('s') ? "'" : "'s"
350
- "#{self}#{possession}"
351
- end
354
+ def possessive!
355
+ replace(possessive)
356
+ end
352
357
 
353
- def possessive!
354
- replace(possessive)
355
- end
358
+ def possessive?
359
+ %w['s s'].any? { |pos| end_with?(pos) }
360
+ end
356
361
 
357
- def possessive?
358
- %w['s s'].any? { |pos| end_with?(pos) }
359
- end
362
+ def push(string)
363
+ replace(concat(string))
364
+ end
360
365
 
361
- def push(string)
362
- replace(concat(string))
363
- end
366
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
367
+ def quote(type = :double, amount = nil)
368
+ if type.is_a?(Integer)
369
+ tmp = amount
370
+ amount = type
371
+ type = tmp || :mixed
372
+ else
373
+ amount ||= 1
374
+ end
364
375
 
365
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
366
- def quote(type = :double, amount = nil)
367
- if type.is_a?(Integer)
368
- tmp = amount
369
- amount = type
370
- type = tmp || :mixed
371
- else
372
- amount ||= 1
373
- end
374
-
375
- case type.to_s
376
- when "'", 'single', 's', '1'
377
- f = "'" * amount
378
- b = f
379
- when '"', 'double', 'd', '2'
380
- f = '"' * amount
381
- b = f
382
- when '`', 'back', 'backtick', 'b', '-1'
383
- f = '`' * amount
384
- b = f
385
- when "`'", 'bracket', 'sb'
386
- f = '`' * amount
387
- b = "'" * amount
388
- when "'\"", 'mixed', 'm', 'Integer'
389
- c = (amount.to_f / 2).to_i
390
- f = '"' * c
391
- b = f
392
-
393
- if amount.odd?
394
- f = "'" + f
395
- b += "'"
376
+ case type.to_s
377
+ when "'", 'single', 's', '1'
378
+ f = "'" * amount
379
+ b = f
380
+ when '"', 'double', 'd', '2'
381
+ f = '"' * amount
382
+ b = f
383
+ when '`', 'back', 'backtick', 'b', '-1'
384
+ f = '`' * amount
385
+ b = f
386
+ when "`'", 'bracket', 'sb'
387
+ f = '`' * amount
388
+ b = "'" * amount
389
+ when "'\"", 'mixed', 'm', 'Integer'
390
+ c = (amount.to_f / 2).to_i
391
+ f = '"' * c
392
+ b = f
393
+
394
+ if amount.odd?
395
+ f = "'" + f
396
+ b += "'"
397
+ end
398
+ else
399
+ raise ArgumentError, "Invalid quote type: #{type.inspect}"
396
400
  end
397
- else
398
- raise ArgumentError, "Invalid quote type: #{type.inspect}"
399
- end
400
401
 
401
- "#{f}#{self}#{b}"
402
- end
403
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
402
+ "#{f}#{self}#{b}"
403
+ end
404
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
404
405
 
405
- def quote!(type = :double, amount = nil)
406
- replace(quote(type, amount))
407
- end
406
+ def quote!(type = :double, amount = nil)
407
+ replace(quote(type, amount))
408
+ end
408
409
 
409
- def remove(*patterns)
410
- dup.remove!(*patterns)
411
- end
410
+ def remove(*patterns)
411
+ dup.remove!(*patterns)
412
+ end
412
413
 
413
- def remove!(*patterns)
414
- patterns.each_with_object(self) do |pat, str|
415
- pat.is_a?(Range) ? str.slice!(pat) : str.gsub!(pat, '')
414
+ def remove!(*patterns)
415
+ patterns.each_with_object(self) do |pat, str|
416
+ pat.is_a?(Range) ? str.slice!(pat) : str.gsub!(pat, '')
417
+ end
416
418
  end
417
- end
418
419
 
419
- def remove_tags
420
- dup.remove_tags!
421
- end
420
+ def remove_tags
421
+ dup.remove_tags!
422
+ end
422
423
 
423
- def remove_tags!
424
- gsub!(%r{<\/?[^>]*>}, '') || self
425
- end
424
+ def remove_tags!
425
+ gsub!(%r{<\/?[^>]*>}, '') || self
426
+ end
426
427
 
427
- def rotate(amount = 1)
428
- dup.rotate!(amount)
429
- end
428
+ def rotate(amount = 1)
429
+ dup.rotate!(amount)
430
+ end
430
431
 
431
- def rotate!(amount = 1)
432
- amount += size if amount.negative?
433
- slice!(amount, size - amount) + slice!(0, amount)
434
- end
432
+ def rotate!(amount = 1)
433
+ amount += size if amount.negative?
434
+ slice!(amount, size - amount) + slice!(0, amount)
435
+ end
435
436
 
436
- def sample(separator = ' ')
437
- split(separator).sample
438
- end
437
+ def sample(separator = ' ')
438
+ split(separator).sample
439
+ end
439
440
 
440
- def sample!(separator = ' ')
441
- replace(sample(separator))
442
- end
441
+ def sample!(separator = ' ')
442
+ replace(sample(separator))
443
+ end
443
444
 
444
- def shift(*patterns)
445
- dup.shift!(*patterns)
446
- end
445
+ def shift(*patterns)
446
+ dup.shift!(*patterns)
447
+ end
447
448
 
448
- def shift!(*patterns)
449
- return self[0] if patterns.empty?
449
+ def shift!(*patterns)
450
+ return self[0] if patterns.empty?
450
451
 
451
- patterns.each_with_object(self) { |pat, str| str.sub!(pat, '') }
452
- end
452
+ patterns.each_with_object(self) { |pat, str| str.sub!(pat, '') }
453
+ end
453
454
 
454
- def shuffle(separator = '')
455
- split(separator).shuffle.join
456
- end
455
+ def shuffle(separator = '')
456
+ split(separator).shuffle.join
457
+ end
457
458
 
458
- def shuffle!(separator = '')
459
- replace(shuffle(separator))
460
- end
459
+ def shuffle!(separator = '')
460
+ replace(shuffle(separator))
461
+ end
461
462
 
462
- def sift(keep)
463
- keep = case keep
464
- when String then keep.chars
465
- when Array then keep.map(&:to_s)
466
- when Range then keep.to_a.map(&:to_s)
467
- else raise TypeError, "Invalid parameter: #{keep.inspect}"
468
- end
463
+ def sift(keep)
464
+ keep = case keep
465
+ when String then keep.chars
466
+ when Array then keep.map(&:to_s)
467
+ when Range then keep.to_a.map(&:to_s)
468
+ else raise TypeError, "Invalid parameter: #{keep.inspect}"
469
+ end
469
470
 
470
- chars.keep_if { |chr| keep.include?(chr) }.join
471
- end
471
+ chars.keep_if { |chr| keep.include?(chr) }.join
472
+ end
472
473
 
473
- def sift!(keep)
474
- replace(sift(keep))
475
- end
474
+ def sift!(keep)
475
+ replace(sift(keep))
476
+ end
476
477
 
477
- def slugify
478
- dup.slugify!
479
- end
478
+ def slugify
479
+ dup.slugify!
480
+ end
480
481
 
481
- def slugify!
482
- gsub!(/[^\x00-\x7F]+/, '')
483
- gsub!(/[^\w_ \-]+/i, '')
484
- gsub!(/[ \-]+/i, '-')
485
- gsub!(/^\-|\-$/i, '')
486
- downcase! || self
487
- end
482
+ def slugify!
483
+ gsub!(/[^\x00-\x7F]+/, '')
484
+ gsub!(/[^\w_ \-]+/i, '')
485
+ gsub!(/[ \-]+/i, '-')
486
+ gsub!(/^\-|\-$/i, '')
487
+ downcase! || self
488
+ end
488
489
 
489
- def squish
490
- dup.squish!
491
- end
490
+ def squish
491
+ dup.squish!
492
+ end
492
493
 
493
- def squish!
494
- strip!
495
- gsub!(/\s+/, ' ') || self
496
- end
494
+ def squish!
495
+ strip!
496
+ gsub!(/\s+/, ' ') || self
497
+ end
497
498
 
498
- def sort
499
- chars.sort.join
500
- end
499
+ def sort
500
+ chars.sort.join
501
+ end
501
502
 
502
- def sort!
503
- replace(sort)
504
- end
503
+ def sort!
504
+ replace(sort)
505
+ end
505
506
 
506
- def titleize
507
- dup.titleize!
508
- end
507
+ def titleize
508
+ dup.titleize!
509
+ end
509
510
 
510
- alias titlecase titleize
511
+ alias titlecase titleize
511
512
 
512
- def titleize!
513
- underscore!
514
- humanize!
515
- gsub!(/\b(?<!['’`])[a-z]/) { $&.capitalize } || self
516
- end
513
+ def titleize!
514
+ underscore!
515
+ humanize!
516
+ gsub!(/\b(?<!['’`])[a-z]/) { $&.capitalize } || self
517
+ end
517
518
 
518
- alias titlecase! titleize!
519
+ alias titlecase! titleize!
519
520
 
520
- def to(position)
521
- self[0..position]
522
- end
521
+ def to(position)
522
+ self[0..position]
523
+ end
523
524
 
524
- def transliterize
525
- dup.transliterize!
526
- end
525
+ def transliterize
526
+ dup.transliterize!
527
+ end
527
528
 
528
- def transliterize!
529
- TRANSLITERATIONS.each_with_object(self) { |(k, v), str| str.gsub!(k, v) }
530
- end
529
+ def transliterize!
530
+ TRANSLITERATIONS.each_with_object(self) { |(k, v), str| str.gsub!(k, v) }
531
+ end
531
532
 
532
- def truncate(truncate_at, options = {})
533
- return dup unless length > truncate_at
533
+ def truncate(truncate_at, options = {})
534
+ return dup unless length > truncate_at
534
535
 
535
- seperator = options[:separator]
536
- omission = options[:omission] || '...'
537
- size_with_room_for_omission = truncate_at - omission.length
536
+ seperator = options[:separator]
537
+ omission = options[:omission] || '...'
538
+ size_with_room_for_omission = truncate_at - omission.length
538
539
 
539
- stop = if seperator
540
- rindex(seperator || '', size_with_room_for_omission) || size_with_room_for_omission
541
- else
542
- size_with_room_for_omission
543
- end
540
+ stop = if seperator
541
+ rindex(seperator || '', size_with_room_for_omission) || size_with_room_for_omission
542
+ else
543
+ size_with_room_for_omission
544
+ end
544
545
 
545
- "#{self[0, stop]}#{omission}"
546
- end
546
+ "#{self[0, stop]}#{omission}"
547
+ end
547
548
 
548
- def truncate_words(words_count, options = {})
549
- sep = options[:separator] || /\s+/
550
- sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
551
- return self unless /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m.match?(self)
549
+ def truncate_words(words_count, options = {})
550
+ sep = options[:separator] || /\s+/
551
+ sep = Regexp.escape(sep.to_s) unless sep.is_a(Regexp)
552
+ return self unless /\A((?:.+?#{sep}){#{words_count - 1}}.+?)#{sep}.*/m.match?(self)
552
553
 
553
- "#{::Regexp.last_match(1)}#{options[:omissio] || '...'}"
554
- end
554
+ "#{::Regexp.last_match(1)}#{options[:omissio] || '...'}"
555
+ end
555
556
 
556
- def underscore
557
- dup.underscore!
558
- end
557
+ def underscore
558
+ dup.underscore!
559
+ end
559
560
 
560
- alias snakecase underscore
561
+ alias snakecase underscore
561
562
 
562
- def underscore!
563
- camelize!
564
- gsub!(/::/, '/')
565
- gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
566
- gsub!(/([a-z\d])([A-Z])/, '\1_\2')
567
- tr!('-', '_')
568
- downcase! || self
569
- end
563
+ def underscore!
564
+ camelize!
565
+ gsub!(/::/, '/')
566
+ gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
567
+ gsub!(/([a-z\d])([A-Z])/, '\1_\2')
568
+ tr!('-', '_')
569
+ downcase! || self
570
+ end
570
571
 
571
- alias snakecase! underscore!
572
+ alias snakecase! underscore!
572
573
 
573
- def unpollute(delimiter = '^--^--^')
574
- dup.unpollute!(delimiter)
575
- end
574
+ def unpollute(delimiter = '^--^--^')
575
+ dup.unpollute!(delimiter)
576
+ end
576
577
 
577
- def unpollute!(delimiter = '^--^--^')
578
- gsub!(delimiter, '') || self
579
- end
578
+ def unpollute!(delimiter = '^--^--^')
579
+ gsub!(delimiter, '') || self
580
+ end
580
581
 
581
- def upcase?
582
- upcase == self
583
- end
582
+ def upcase?
583
+ upcase == self
584
+ end
584
585
 
585
- def unshift(*patterns)
586
- patterns.each_with_object('') { |pat, str| str << pat }
587
- .concat(self)
588
- end
586
+ def unshift(*patterns)
587
+ patterns.each_with_object('') { |pat, str| str << pat }
588
+ .concat(self)
589
+ end
589
590
 
590
- def unshift!(*patterns)
591
- replace(unshift(*patterns))
592
- end
591
+ def unshift!(*patterns)
592
+ replace(unshift(*patterns))
593
+ end
593
594
 
594
- def unquote
595
- dup.unquote!
596
- end
595
+ def unquote
596
+ dup.unquote!
597
+ end
597
598
 
598
- def unquote!
599
- [0, -1].each do |i|
600
- case self[i, 1]
601
- when "'", '"', '`' then self[i] = ''
599
+ def unquote!
600
+ [0, -1].each do |i|
601
+ case self[i, 1]
602
+ when "'", '"', '`' then self[i] = ''
603
+ end
602
604
  end
603
- end
604
605
 
605
- self
606
- end
606
+ self
607
+ end
607
608
 
608
- def words
609
- split(/\s+/)
610
- end
609
+ def words
610
+ split(/\s+/)
611
+ end
611
612
 
612
- def words_without_punctuation
613
- str = dup
614
- str.gsub!(%r{[.?¿¡…!,::;—"。?!、‘“”„«»〈〉《》,/\[\]]}, ' ')
615
- str.gsub!('- ', ' ')
616
- str.squeeze!(' ')
617
- str.strip!
618
- str.words
619
- end
613
+ def words_without_punctuation
614
+ str = dup
615
+ str.gsub!(%r{[.?¿¡…!,::;—"。?!、‘“”„«»〈〉《》,/\[\]]}, ' ')
616
+ str.gsub!('- ', ' ')
617
+ str.squeeze!(' ')
618
+ str.strip!
619
+ str.words
620
+ end
620
621
 
621
- def variablize
622
- "@#{gsub(/\W/, '_')}"
623
- end
622
+ def variablize
623
+ "@#{gsub(/\W/, '_')}"
624
+ end
624
625
 
625
- def variablize!
626
- replace(variablize)
627
- end
626
+ def variablize!
627
+ replace(variablize)
628
+ end
628
629
 
629
- alias ends_with? end_with?
630
- alias starts_with? start_with?
630
+ alias ends_with? end_with?
631
+ alias starts_with? start_with?
631
632
 
633
+ end
632
634
  end