lucky_case 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f8bf7cdb1dcc0214e91e6a2818262ff49b4f0aac27cf39d09d19b6f356f8c4f
4
- data.tar.gz: cb8ccfab6f18eba90fa37b4ba364d2571f417e21a885e7c32760145696ad3f14
3
+ metadata.gz: bfe36f3ecf272ce46d7350964f6396949e54b49544e2d4a886b27cba698acedd
4
+ data.tar.gz: 99e2745316e403bd0c1258bfc5db260da120b3215f224d38efee03a5bcc46392
5
5
  SHA512:
6
- metadata.gz: fca494255aeeee1f77928f0b6cce87252311e1459a59ea2b70e14ea2df3b0a5b6c9998734f73f0199ee9ecc97c3b6fc7a1f5a41aa7e054dd9def83014d44da63
7
- data.tar.gz: 52644493a0bc2adedd7aee6059fccf0aa3c7c14e0a15f91188f5e0a09167dca7a507d4cb18fcbd5f42f7d88a384eed2cb967a86438c7ea97d0be45dc6c689521
6
+ metadata.gz: 704d45b0cd6df44c2097b467759a0a4ec58d42b0fdbeed78b3cf11f8012b68aae9fd9beb2bb23fa25224338d876e93daf1001b7616491665224c6ebe45dcdbd1
7
+ data.tar.gz: 60d487477cf8d5515ec135a370aaa97b78665ad6ec060f63a29e0190858ea7ddc5eb09dd1642d15da2ff3bc03c378878e41e2a228649bb646ecd5dbb70f901df
data/README.md CHANGED
@@ -25,21 +25,27 @@ Useful when working with conventions, where class names, method names and file n
25
25
 
26
26
  You can either use the static LuckyCase class with its method or optionally monkey patch the String class.
27
27
 
28
- ### Use the static class only
28
+ ### Approach 1: Using the static class
29
29
  ```ruby
30
30
  require 'lucky_case'
31
31
 
32
32
  # converters
33
- LuckyCase.snake_case('ExamplePascalString') # => 'example_pascal_string'
34
- LuckyCase.upper_snake_case('Example-Train-String') # => 'EXAMPLE_TRAIN_STRING'
35
- LuckyCase.pascal_case('example_snake_string') # => 'ExampleSnakeString'
36
- LuckyCase.camel_case('example-dash-string') # => 'exampleDashString'
37
- LuckyCase.dash_case('ExamplePascalString') # => 'example-pascal-string'
38
- LuckyCase.upper_dash_case('ExamplePascalString') # => 'EXAMPLE-PASCAL-STRING'
39
- LuckyCase.train_case('example_snake_string') # => 'Example-Snake-String'
33
+ LuckyCase.snake_case('PascalToSnake') # => 'pascal_to_snake'
34
+ LuckyCase.upper_snake_case('Train-To-Upper-Snake') # => 'TRAIN_TO_UPPER_SNAKE'
35
+ LuckyCase.pascal_case('snake_to_pascal') # => 'SnakeToPascal'
36
+ LuckyCase.camel_case('dash-to-camel-case') # => 'dashToCamelCase'
37
+ LuckyCase.dash_case('PascalToDashCase') # => 'pascal-to-dash-case'
38
+ LuckyCase.upper_dash_case('PascalToUpperDash') # => 'PASCAL-TO-UPPER-DASH'
39
+ LuckyCase.train_case('snake_to_train_case') # => 'Snake-To-Train-Case'
40
+ LuckyCase.word_case('PascalToWordCase') # => 'pascal to word case'
41
+ LuckyCase.upper_word_case('PascalToUpperWord') # => 'PASCAL TO UPPER WORD'
42
+ LuckyCase.capital_word_case('snake_to_capital_word') # => 'Snake To Capital Word'
43
+ LuckyCase.sentence_case('snake_to_sentence_case') # => 'Snake to sentence case'
40
44
  LuckyCase.mixed_case('example_snake_string') # => 'Example-snake_STRING'
45
+
41
46
  # converter by type
42
47
  LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
48
+
43
49
  # transformers
44
50
  LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
45
51
  LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
@@ -51,29 +57,41 @@ LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
51
57
  LuckyCase.constantize('some/path_example/folder') # => Some::PathExample::Folder
52
58
  LuckyCase.deconstantize(SomeConstant) # => 'some_constant'
53
59
  LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
54
- # identifier
60
+
61
+ # identifiers
55
62
  LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
56
- LuckyCase.cases('multiple') # => [ :snake_case, :camel_case, :dash_case ]
63
+ LuckyCase.cases('validformultiple') # => [ :snake_case, :camel_case, :dash_case, :word_case ]
64
+
57
65
  # checkers
58
66
  LuckyCase.snake_case?('valid_snake_case') # => true
59
- LuckyCase.upper_snake_case?('inValidSnakeCase') # => false
67
+ LuckyCase.upper_snake_case?('UPPER_SNAKE') # => true
60
68
  LuckyCase.pascal_case?('PascalCase') # => true
61
69
  LuckyCase.camel_case?('camelCase') # => true
62
70
  LuckyCase.dash_case?('dash-case') # => true
63
71
  LuckyCase.upper_dash_case?('DASH-CASE') # => true
64
72
  LuckyCase.train_case?('Train-Case') # => true
73
+ LuckyCase.word_case?('word case') # => true
74
+ LuckyCase.upper_word_case?('UPPER WORD CASE') # => true
75
+ LuckyCase.capital_word_case?('Capital Word Case') # => true
76
+ LuckyCase.sentence_case?('Sentence case string') # => true
65
77
  LuckyCase.mixed_case?('mixed_Case') # => true
66
78
  LuckyCase.upper_case?('UPPER50984') # => true
67
- LuckyCase.lower_case?('mixed_Case') # => true
79
+ LuckyCase.lower_case?('lower_cheese') # => true
68
80
  LuckyCase.capital?('Some') # => true
69
81
  LuckyCase.capitalized?('some') # => false
82
+ LuckyCase.valid_case_type?(:snake_case) # => true
83
+ LuckyCase.valid_case_type?(:apple_case) # => false
84
+ LuckyCase.valid_case_string?('validString') # => true
85
+ LuckyCase.valid_case_string?('1nV4lid$tring') # => false
70
86
  ```
71
87
 
72
- ### Monkey patch the string class
88
+ ### Approach 2: Monkey patch the string class
73
89
 
74
- With monkey patching you can access the same methods (except deconstantize) of LuckyCase directly from strings.
90
+ With monkey patching you can access the same methods (except deconstantize, valid_case_type?) of LuckyCase directly from strings.
75
91
  Additionally they provide versions with exclamation mark for direct manipulation.
76
92
 
93
+ Because the method #case is so general and could lead to conflicts, it is called #letter_case here.
94
+
77
95
  ```ruby
78
96
  require 'lucky_case/string'
79
97
 
@@ -82,9 +100,17 @@ a = 'ExampleString'
82
100
  a.pascal_case? # => true
83
101
  a.snake_case # => 'example_string'
84
102
  a # => 'ExampleString'
103
+
85
104
  # string variable manipulation
86
105
  a.snake_case! # => 'example_string'
87
106
  a # => 'example_string'
107
+ ...
108
+
109
+ # identifiers
110
+ # got a other method name here because 'case' might be to common and cause conflicts
111
+ b = 'example'
112
+ b.letter_case # => :snake_case
113
+ b.letter_cases # => [ :snake_case, :camel_case, :dash_case, :word_case ]
88
114
  ```
89
115
 
90
116
 
@@ -18,7 +18,11 @@ module LuckyCase
18
18
  dash_case: /^([[:lower:]]){1}[[:lower:]\-0-9]*[[:lower:]0-9]+$/,
19
19
  upper_dash_case: /^([[:upper:]]){1}[[:upper:]\-0-9]*[[:upper:]0-9]+$/,
20
20
  train_case: /^([[:upper:]][[:lower:]0-9]*\-|[0-9]+\-)*([[:upper:]][[:lower:]0-9]*)$/,
21
- mixed_case: /^[[:upper:][:lower:]][[:upper:][:lower:]_\-0-9]*$/,
21
+ word_case: /^[[:lower:]]{1}[[:lower:] 0-9]+$/,
22
+ upper_word_case: /^[[:upper:]]{1}[[:upper:] 0-9]+$/,
23
+ capital_word_case: /^([[:upper:]][[:lower:]0-9]*\ |[0-9]+\ )*([[:upper:]][[:lower:]0-9]*)$/,
24
+ sentence_case: /^[[:upper:]]{1}[[:lower:] 0-9]+$/,
25
+ mixed_case: /^[[:upper:][:lower:]][[:upper:][:lower:]_\-0-9 ]*$/,
22
26
  }
23
27
 
24
28
  FORMATS = {
@@ -97,11 +101,31 @@ module LuckyCase
97
101
  raise InvalidCaseError.new error_message
98
102
  end
99
103
 
104
+ # Check if given case type is a valid case type
105
+ #
106
+ # @param [Symbol, String] case_type
107
+ # @return [Boolean]
108
+ def self.valid_case_type?(case_type)
109
+ if CASES.keys.include? case_type.to_sym
110
+ true
111
+ else
112
+ false
113
+ end
114
+ end
115
+
116
+ # Check if the string matches any of the available cases
117
+ #
118
+ # @param [String] case_type
119
+ # @return [Boolean]
120
+ def self.valid_case_string?(string)
121
+ self.case(string) != nil
122
+ end
123
+
100
124
  #----------------------------------------------------------------------------------------------------
101
125
  # UPPER CASE
102
126
  #----------------------------------------------------------------------------------------------------
103
127
 
104
- # Converts all characters inside the string
128
+ # Convert all characters inside the string
105
129
  # into upper case
106
130
  #
107
131
  # @example conversion
@@ -113,7 +137,7 @@ module LuckyCase
113
137
  string.upcase
114
138
  end
115
139
 
116
- # Checks if all characters inside the string are upper case
140
+ # Check if all characters inside the string are upper case
117
141
  #
118
142
  # @param [String] string to check
119
143
  # @return [Boolean]
@@ -125,7 +149,7 @@ module LuckyCase
125
149
  # LOWER CASE
126
150
  #----------------------------------------------------------------------------------------------------
127
151
 
128
- # Converts all characters inside the string
152
+ # Convert all characters inside the string
129
153
  # into lower case
130
154
  #
131
155
  # @example conversion
@@ -137,7 +161,7 @@ module LuckyCase
137
161
  string.downcase
138
162
  end
139
163
 
140
- # Checks if all characters inside the string are lower case
164
+ # Check if all characters inside the string are lower case
141
165
  #
142
166
  # @param [String] string to check
143
167
  # @return [Boolean]
@@ -149,7 +173,7 @@ module LuckyCase
149
173
  # SNAKE CASE
150
174
  #----------------------------------------------------------------------------------------------------
151
175
 
152
- # Converts the given string from any case
176
+ # Convert the given string from any case
153
177
  # into snake case
154
178
  #
155
179
  # @example conversion
@@ -168,7 +192,7 @@ module LuckyCase
168
192
  end
169
193
  end
170
194
 
171
- # Checks if the string is snake case
195
+ # Check if the string is snake case
172
196
  #
173
197
  # @param [String] string to check
174
198
  # @param [Boolean] allow_prefixed_underscores
@@ -182,7 +206,7 @@ module LuckyCase
182
206
  _case_match? s, :snake_case
183
207
  end
184
208
 
185
- # Converts the given string from any case
209
+ # Convert the given string from any case
186
210
  # into upper snake case
187
211
  #
188
212
  # @example conversion
@@ -201,7 +225,7 @@ module LuckyCase
201
225
  end
202
226
  end
203
227
 
204
- # Checks if the string is upper snake case
228
+ # Check if the string is upper snake case
205
229
  #
206
230
  # @param [String] string to check
207
231
  # @param [Boolean] allow_prefixed_underscores
@@ -219,7 +243,7 @@ module LuckyCase
219
243
  # PASCAL CASE
220
244
  #----------------------------------------------------------------------------------------------------
221
245
 
222
- # Converts the given string from any case
246
+ # Convert the given string from any case
223
247
  # into pascal case
224
248
  #
225
249
  # @example conversion
@@ -238,7 +262,7 @@ module LuckyCase
238
262
  end
239
263
  end
240
264
 
241
- # Checks if the string is upper pascal case
265
+ # Check if the string is upper pascal case
242
266
  #
243
267
  # @param [String] string to check
244
268
  # @param [Boolean] allow_prefixed_underscores
@@ -256,7 +280,7 @@ module LuckyCase
256
280
  # CAMEL CASE
257
281
  #----------------------------------------------------------------------------------------------------
258
282
 
259
- # Converts the given string from any case
283
+ # Convert the given string from any case
260
284
  # into camel case
261
285
  #
262
286
  # @example conversion
@@ -275,7 +299,7 @@ module LuckyCase
275
299
  end
276
300
  end
277
301
 
278
- # Checks if the string is camel case
302
+ # Check if the string is camel case
279
303
  #
280
304
  # @param [String] string to check
281
305
  # @param [Boolean] allow_prefixed_underscores
@@ -293,7 +317,7 @@ module LuckyCase
293
317
  # DASH CASE
294
318
  #----------------------------------------------------------------------------------------------------
295
319
 
296
- # Converts the given string from any case
320
+ # Convert the given string from any case
297
321
  # into dash case
298
322
  #
299
323
  # @example conversion
@@ -312,7 +336,7 @@ module LuckyCase
312
336
  end
313
337
  end
314
338
 
315
- # Checks if the string is dash case
339
+ # Check if the string is dash case
316
340
  #
317
341
  # @param [String] string to check
318
342
  # @param [Boolean] allow_prefixed_underscores
@@ -326,7 +350,7 @@ module LuckyCase
326
350
  _case_match? s, :dash_case
327
351
  end
328
352
 
329
- # Converts the given string from any case
353
+ # Convert the given string from any case
330
354
  # into upper dash case
331
355
  #
332
356
  # @example conversion
@@ -340,7 +364,7 @@ module LuckyCase
340
364
  upper_case s
341
365
  end
342
366
 
343
- # Checks if the string is upper dash case
367
+ # Check if the string is upper dash case
344
368
  #
345
369
  # @param [String] string to check
346
370
  # @param [Boolean] allow_prefixed_underscores
@@ -358,7 +382,7 @@ module LuckyCase
358
382
  # TRAIN CASE
359
383
  #----------------------------------------------------------------------------------------------------
360
384
 
361
- # Converts the given string from any case
385
+ # Convert the given string from any case
362
386
  # into train case
363
387
  #
364
388
  # @example conversion
@@ -377,7 +401,7 @@ module LuckyCase
377
401
  end
378
402
  end
379
403
 
380
- # Checks if the string is train case
404
+ # Check if the string is train case
381
405
  #
382
406
  # @param [String] string to check
383
407
  # @param [Boolean] allow_prefixed_underscores
@@ -391,11 +415,151 @@ module LuckyCase
391
415
  _case_match? s, :train_case
392
416
  end
393
417
 
418
+ #----------------------------------------------------------------------------------------------------
419
+ # WORD CASE
420
+ #----------------------------------------------------------------------------------------------------
421
+
422
+ # Convert the given string from any case
423
+ # into word case
424
+ #
425
+ # @example conversion
426
+ # 'this-isAnExample_string' => 'this is an example string'
427
+ #
428
+ # @param [String] string to convert
429
+ # @param [Boolean] preserve_prefixed_underscores
430
+ # @return [String]
431
+ def self.word_case(string, preserve_prefixed_underscores: true)
432
+ a = split_case_string string
433
+ converted = a.join(' ')
434
+ if preserve_prefixed_underscores
435
+ underscores_at_start(string) + converted
436
+ else
437
+ converted
438
+ end
439
+ end
440
+
441
+ # Check if the string is word case
442
+ #
443
+ # @param [String] string to check
444
+ # @param [Boolean] allow_prefixed_underscores
445
+ # @return [Boolean]
446
+ def self.word_case?(string, allow_prefixed_underscores: true)
447
+ s = if allow_prefixed_underscores
448
+ cut_underscores_at_start string
449
+ else
450
+ string
451
+ end
452
+ _case_match? s, :word_case
453
+ end
454
+
455
+ # Convert the given string from any case
456
+ # into upper word case
457
+ #
458
+ # @example conversion
459
+ # 'this-isAnExample_string' => 'THIS IS AN EXAMPLE STRING'
460
+ #
461
+ # @param [String] string to convert
462
+ # @param [Boolean] preserve_prefixed_underscores
463
+ # @return [String]
464
+ def self.upper_word_case(string, preserve_prefixed_underscores: true)
465
+ a = split_case_string string
466
+ converted = a.map { |e| upper_case e }.join(' ')
467
+ if preserve_prefixed_underscores
468
+ underscores_at_start(string) + converted
469
+ else
470
+ converted
471
+ end
472
+ end
473
+
474
+ # Check if the string is upper word case
475
+ #
476
+ # @param [String] string to check
477
+ # @param [Boolean] allow_prefixed_underscores
478
+ # @return [Boolean]
479
+ def self.upper_word_case?(string, allow_prefixed_underscores: true)
480
+ s = if allow_prefixed_underscores
481
+ cut_underscores_at_start string
482
+ else
483
+ string
484
+ end
485
+ _case_match? s, :upper_word_case
486
+ end
487
+
488
+ # Convert the given string from any case
489
+ # into capital word case
490
+ #
491
+ # @example conversion
492
+ # 'this-isAnExample_string' => 'This Is An Example String'
493
+ #
494
+ # @param [String] string to convert
495
+ # @param [Boolean] preserve_prefixed_underscores
496
+ # @return [String]
497
+ def self.capital_word_case(string, preserve_prefixed_underscores: true)
498
+ a = split_case_string string
499
+ converted = a.map { |e| capital e }.join(' ')
500
+ if preserve_prefixed_underscores
501
+ underscores_at_start(string) + converted
502
+ else
503
+ converted
504
+ end
505
+ end
506
+
507
+ # Check if the string is capital word case
508
+ #
509
+ # @param [String] string to check
510
+ # @param [Boolean] allow_prefixed_underscores
511
+ # @return [Boolean]
512
+ def self.capital_word_case?(string, allow_prefixed_underscores: true)
513
+ s = if allow_prefixed_underscores
514
+ cut_underscores_at_start string
515
+ else
516
+ string
517
+ end
518
+ _case_match? s, :capital_word_case
519
+ end
520
+
521
+ #----------------------------------------------------------------------------------------------------
522
+ # SENTENCE CASE
523
+ #----------------------------------------------------------------------------------------------------
524
+
525
+ # Convert the given string from any case
526
+ # into sentence case
527
+ #
528
+ # @example conversion
529
+ # 'this-isAnExample_string' => 'This is an example string'
530
+ #
531
+ # @param [String] string to convert
532
+ # @param [Boolean] preserve_prefixed_underscores
533
+ # @return [String]
534
+ def self.sentence_case(string, preserve_prefixed_underscores: true)
535
+ a = split_case_string string
536
+ converted = capital(a.join(' '))
537
+ if preserve_prefixed_underscores
538
+ underscores_at_start(string) + converted
539
+ else
540
+ converted
541
+ end
542
+ end
543
+
544
+ # Check if the string is sentence case
545
+ #
546
+ # @param [String] string to check
547
+ # @param [Boolean] allow_prefixed_underscores
548
+ # @return [Boolean]
549
+ def self.sentence_case?(string, allow_prefixed_underscores: true)
550
+ s = if allow_prefixed_underscores
551
+ cut_underscores_at_start string
552
+ else
553
+ string
554
+ end
555
+ _case_match? s, :sentence_case
556
+ end
557
+
394
558
  #----------------------------------------------------------------------------------------------------
395
559
  # CAPITALIZE
396
560
  #----------------------------------------------------------------------------------------------------
397
561
 
398
- # Converts the first character to capital
562
+ # Convert the first character to capital
399
563
  #
400
564
  # @param [String] string to convert
401
565
  # @param [Boolean] skip_prefixed_underscores
@@ -415,7 +579,7 @@ module LuckyCase
415
579
  end
416
580
  end
417
581
 
418
- # Converts the first character to capital
582
+ # Convert the first character to capital
419
583
  #
420
584
  # @param [String] string to convert
421
585
  # @param [Boolean] skip_prefixed_underscores
@@ -424,7 +588,7 @@ module LuckyCase
424
588
  capital string, skip_prefixed_underscores: skip_prefixed_underscores
425
589
  end
426
590
 
427
- # Checks if the strings first character is a capital letter
591
+ # Check if the strings first character is a capital letter
428
592
  #
429
593
  # @param [String] string to check
430
594
  # @param [Boolean] skip_prefixed_underscores
@@ -438,7 +602,7 @@ module LuckyCase
438
602
  _case_match? s, :capital
439
603
  end
440
604
 
441
- # Checks if the strings first character is a capital letter
605
+ # Check if the strings first character is a capital letter
442
606
  #
443
607
  # @param [String] string to check
444
608
  # @param [Boolean] skip_prefixed_underscores
@@ -451,7 +615,7 @@ module LuckyCase
451
615
  # MIXED CASE
452
616
  #----------------------------------------------------------------------------------------------------
453
617
 
454
- # Converts the given string from any case
618
+ # Convert the given string from any case
455
619
  # into mixed case
456
620
  #
457
621
  # @example conversion
@@ -473,7 +637,7 @@ module LuckyCase
473
637
  end
474
638
  end
475
639
 
476
- # Checks if the string is a valid mixed case (without special characters!)
640
+ # Check if the string is a valid mixed case (without special characters!)
477
641
  #
478
642
  # @param [String] string to check
479
643
  # @return [Boolean]
@@ -528,7 +692,7 @@ module LuckyCase
528
692
  # CONSTANTIZE
529
693
  #----------------------------------------------------------------------------------------------------
530
694
 
531
- # Converts the string from any case
695
+ # Convert the string from any case
532
696
  # into pascal case and casts it into a constant
533
697
  #
534
698
  # @example conversion
@@ -539,7 +703,7 @@ module LuckyCase
539
703
  # @param [Boolean] preserve_prefixed_underscores
540
704
  # @return [Constant]
541
705
  def self.constantize(string)
542
- s = string.gsub('/','::')
706
+ s = string.gsub('/', '::')
543
707
  constants = if s.include? '::'
544
708
  s.split('::')
545
709
  else
@@ -586,7 +750,7 @@ module LuckyCase
586
750
  #----------------------------------------------------------------------------------------------------
587
751
  # HELPERS
588
752
  #----------------------------------------------------------------------------------------------------
589
-
753
+
590
754
  # Return string without underscores at the start
591
755
  #
592
756
  # @param [String] string
@@ -627,6 +791,7 @@ module LuckyCase
627
791
  def self.split_case_string(string)
628
792
  s = cut_underscores_at_start string
629
793
  s = s.gsub(/([[:upper:]])/, '_\1') unless upper_case? s # prepend all upper characters with underscore
794
+ s = s.gsub(' ', '_') # replace all spaces with underscore
630
795
  s = s.gsub('-', '_') # replace all dashes with underscore
631
796
  s = cut_underscores_at_start s
632
797
  s.downcase.split('_').reject(&:empty?) # split everything by underscore
@@ -46,11 +46,18 @@ class String
46
46
  set_self_value self.convert_case(case_type, preserve_prefixed_underscores: preserve_prefixed_underscores)
47
47
  end
48
48
 
49
+ # Check if the string matches any of the available cases
50
+ #
51
+ # @return [Boolean]
52
+ def valid_case_string?()
53
+ LuckyCase.case(self) != nil
54
+ end
55
+
49
56
  #----------------------------------------------------------------------------------------------------
50
57
  # UPPER CASE
51
58
  #----------------------------------------------------------------------------------------------------
52
59
 
53
- # Converts all characters inside the string
60
+ # Convert all characters inside the string
54
61
  # into upper case
55
62
  #
56
63
  # @example conversion
@@ -65,7 +72,7 @@ class String
65
72
  set_self_value self.upper_case
66
73
  end
67
74
 
68
- # Checks if all characters inside the string are upper case
75
+ # Check if all characters inside the string are upper case
69
76
  #
70
77
  # @return [Boolean]
71
78
  def upper_case?()
@@ -76,7 +83,7 @@ class String
76
83
  # LOWER CASE
77
84
  #----------------------------------------------------------------------------------------------------
78
85
 
79
- # Converts all characters inside the string
86
+ # Convert all characters inside the string
80
87
  # into lower case
81
88
  #
82
89
  # @example conversion
@@ -91,7 +98,7 @@ class String
91
98
  set_self_value self.lower_case
92
99
  end
93
100
 
94
- # Checks if all characters inside the string are lower case
101
+ # Check if all characters inside the string are lower case
95
102
  #
96
103
  # @return [Boolean]
97
104
  def lower_case?()
@@ -102,7 +109,7 @@ class String
102
109
  # SNAKE CASE
103
110
  #----------------------------------------------------------------------------------------------------
104
111
 
105
- # Converts the given string from any case
112
+ # Convert the given string from any case
106
113
  # into snake case
107
114
  #
108
115
  # @example conversion
@@ -118,7 +125,7 @@ class String
118
125
  set_self_value self.snake_case preserve_prefixed_underscores: preserve_prefixed_underscores
119
126
  end
120
127
 
121
- # Checks if the string is snake case
128
+ # Check if the string is snake case
122
129
  #
123
130
  # @param [Boolean] allow_prefixed_underscores
124
131
  # @return [Boolean]
@@ -126,7 +133,7 @@ class String
126
133
  LuckyCase.snake_case? self, allow_prefixed_underscores: allow_prefixed_underscores
127
134
  end
128
135
 
129
- # Converts the given string from any case
136
+ # Convert the given string from any case
130
137
  # into upper snake case
131
138
  #
132
139
  # @example conversion
@@ -142,7 +149,7 @@ class String
142
149
  set_self_value self.upper_snake_case preserve_prefixed_underscores: preserve_prefixed_underscores
143
150
  end
144
151
 
145
- # Checks if the string is upper snake case
152
+ # Check if the string is upper snake case
146
153
  #
147
154
  # @param [Boolean] allow_prefixed_underscores
148
155
  # @return [Boolean]
@@ -154,7 +161,7 @@ class String
154
161
  # PASCAL CASE
155
162
  #----------------------------------------------------------------------------------------------------
156
163
 
157
- # Converts the given string from any case
164
+ # Convert the given string from any case
158
165
  # into pascal case
159
166
  #
160
167
  # @example conversion
@@ -170,7 +177,7 @@ class String
170
177
  set_self_value self.pascal_case preserve_prefixed_underscores: preserve_prefixed_underscores
171
178
  end
172
179
 
173
- # Checks if the string is upper pascal case
180
+ # Check if the string is upper pascal case
174
181
  #
175
182
  # @param [Boolean] allow_prefixed_underscores
176
183
  # @return [Boolean]
@@ -182,7 +189,7 @@ class String
182
189
  # CAMEL CASE
183
190
  #----------------------------------------------------------------------------------------------------
184
191
 
185
- # Converts the given string from any case
192
+ # Convert the given string from any case
186
193
  # into camel case
187
194
  #
188
195
  # @example conversion
@@ -198,7 +205,7 @@ class String
198
205
  set_self_value self.camel_case preserve_prefixed_underscores: preserve_prefixed_underscores
199
206
  end
200
207
 
201
- # Checks if the string is camel case
208
+ # Check if the string is camel case
202
209
  #
203
210
  # @param [Boolean] allow_prefixed_underscores
204
211
  # @return [Boolean]
@@ -210,7 +217,7 @@ class String
210
217
  # DASH CASE
211
218
  #----------------------------------------------------------------------------------------------------
212
219
 
213
- # Converts the given string from any case
220
+ # Convert the given string from any case
214
221
  # into dash case
215
222
  #
216
223
  # @example conversion
@@ -226,7 +233,7 @@ class String
226
233
  set_self_value self.dash_case preserve_prefixed_underscores: preserve_prefixed_underscores
227
234
  end
228
235
 
229
- # Checks if the string is dash case
236
+ # Check if the string is dash case
230
237
  #
231
238
  # @param [Boolean] allow_prefixed_underscores
232
239
  # @return [Boolean]
@@ -234,7 +241,7 @@ class String
234
241
  LuckyCase.dash_case? self, allow_prefixed_underscores: allow_prefixed_underscores
235
242
  end
236
243
 
237
- # Converts the given string from any case
244
+ # Convert the given string from any case
238
245
  # into upper dash case
239
246
  #
240
247
  # @example conversion
@@ -250,7 +257,7 @@ class String
250
257
  set_self_value self.upper_dash_case preserve_prefixed_underscores: preserve_prefixed_underscores
251
258
  end
252
259
 
253
- # Checks if the string is upper dash case
260
+ # Check if the string is upper dash case
254
261
  #
255
262
  # @param [Boolean] allow_prefixed_underscores
256
263
  # @return [Boolean]
@@ -262,7 +269,7 @@ class String
262
269
  # TRAIN CASE
263
270
  #----------------------------------------------------------------------------------------------------
264
271
 
265
- # Converts the given string from any case
272
+ # Convert the given string from any case
266
273
  # into train case
267
274
  #
268
275
  # @example conversion
@@ -278,7 +285,7 @@ class String
278
285
  set_self_value self.train_case preserve_prefixed_underscores: preserve_prefixed_underscores
279
286
  end
280
287
 
281
- # Checks if the string is train case
288
+ # Check if the string is train case
282
289
  #
283
290
  # @param [Boolean] allow_prefixed_underscores
284
291
  # @return [Boolean]
@@ -286,11 +293,115 @@ class String
286
293
  LuckyCase.train_case? self, allow_prefixed_underscores: allow_prefixed_underscores
287
294
  end
288
295
 
296
+ #----------------------------------------------------------------------------------------------------
297
+ # WORD CASE
298
+ #----------------------------------------------------------------------------------------------------
299
+
300
+ # Convert the given string from any case
301
+ # into word case
302
+ #
303
+ # @example conversion
304
+ # 'this-isAnExample_string' => 'this is an example string'
305
+ #
306
+ # @param [Boolean] preserve_prefixed_underscores
307
+ # @return [String]
308
+ def word_case(preserve_prefixed_underscores: true)
309
+ LuckyCase.word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
310
+ end
311
+
312
+ def word_case!(preserve_prefixed_underscores: true)
313
+ set_self_value self.word_case preserve_prefixed_underscores: preserve_prefixed_underscores
314
+ end
315
+
316
+ # Check if the string is word case
317
+ #
318
+ # @param [Boolean] allow_prefixed_underscores
319
+ # @return [Boolean]
320
+ def word_case?(allow_prefixed_underscores: true)
321
+ LuckyCase.word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
322
+ end
323
+
324
+ # Convert the given string from any case
325
+ # into upper word case
326
+ #
327
+ # @example conversion
328
+ # 'this-isAnExample_string' => 'THIS IS AN EXAMPLE STRING'
329
+ #
330
+ # @param [Boolean] preserve_prefixed_underscores
331
+ # @return [String]
332
+ def upper_word_case(preserve_prefixed_underscores: true)
333
+ LuckyCase.upper_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
334
+ end
335
+
336
+ def upper_word_case!(preserve_prefixed_underscores: true)
337
+ set_self_value self.upper_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
338
+ end
339
+
340
+ # Check if the string is upper word case
341
+ #
342
+ # @param [Boolean] allow_prefixed_underscores
343
+ # @return [Boolean]
344
+ def upper_word_case?(allow_prefixed_underscores: true)
345
+ LuckyCase.upper_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
346
+ end
347
+
348
+ # Convert the given string from any case
349
+ # into capital word case
350
+ #
351
+ # @example conversion
352
+ # 'this-isAnExample_string' => 'This Is An Example String'
353
+ #
354
+ # @param [Boolean] preserve_prefixed_underscores
355
+ # @return [String]
356
+ def capital_word_case(preserve_prefixed_underscores: true)
357
+ LuckyCase.capital_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
358
+ end
359
+
360
+ def capital_word_case!(preserve_prefixed_underscores: true)
361
+ set_self_value self.capital_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
362
+ end
363
+
364
+ # Check if the string is capital word case
365
+ #
366
+ # @param [Boolean] allow_prefixed_underscores
367
+ # @return [Boolean]
368
+ def capital_word_case?(allow_prefixed_underscores: true)
369
+ LuckyCase.capital_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
370
+ end
371
+
372
+ #----------------------------------------------------------------------------------------------------
373
+ # SENTENCE CASE
374
+ #----------------------------------------------------------------------------------------------------
375
+
376
+ # Convert the given string from any case
377
+ # into sentence case
378
+ #
379
+ # @example conversion
380
+ # 'this-isAnExample_string' => 'This is an example string'
381
+ #
382
+ # @param [Boolean] preserve_prefixed_underscores
383
+ # @return [String]
384
+ def sentence_case(preserve_prefixed_underscores: true)
385
+ LuckyCase.sentence_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
386
+ end
387
+
388
+ def sentence_case!(preserve_prefixed_underscores: true)
389
+ set_self_value self.sentence_case preserve_prefixed_underscores: preserve_prefixed_underscores
390
+ end
391
+
392
+ # Check if the string is sentence case
393
+ #
394
+ # @param [Boolean] allow_prefixed_underscores
395
+ # @return [Boolean]
396
+ def sentence_case?(allow_prefixed_underscores: true)
397
+ LuckyCase.sentence_case? self, allow_prefixed_underscores: allow_prefixed_underscores
398
+ end
399
+
289
400
  #----------------------------------------------------------------------------------------------------
290
401
  # CAPITALIZE
291
402
  #----------------------------------------------------------------------------------------------------
292
403
 
293
- # Converts the first character to capital
404
+ # Convert the first character to capital
294
405
  #
295
406
  # @param [Boolean] skip_prefixed_underscores
296
407
  # @return [String]
@@ -298,7 +409,7 @@ class String
298
409
  LuckyCase.capitalize self, skip_prefixed_underscores: skip_prefixed_underscores
299
410
  end
300
411
 
301
- # Converts the first character to capital
412
+ # Convert the first character to capital
302
413
  #
303
414
  # @param [Boolean] skip_prefixed_underscores
304
415
  # @return [String]
@@ -314,7 +425,7 @@ class String
314
425
  self.capital! skip_prefixed_underscores: skip_prefixed_underscores
315
426
  end
316
427
 
317
- # Checks if the strings first character is a capital letter
428
+ # Check if the strings first character is a capital letter
318
429
  #
319
430
  # @param [Boolean] skip_prefixed_underscores
320
431
  # @return [Boolean]
@@ -322,7 +433,7 @@ class String
322
433
  LuckyCase.capital? self, skip_prefixed_underscores: skip_prefixed_underscores
323
434
  end
324
435
 
325
- # Checks if the strings first character is a capital letter
436
+ # Check if the strings first character is a capital letter
326
437
  #
327
438
  # @param [Boolean] skip_prefixed_underscores
328
439
  # @return [Boolean]
@@ -334,7 +445,7 @@ class String
334
445
  # MIXED CASE
335
446
  #----------------------------------------------------------------------------------------------------
336
447
 
337
- # Converts the given string from any case
448
+ # Convert the given string from any case
338
449
  # into mixed case
339
450
  #
340
451
  # @example conversion
@@ -350,7 +461,7 @@ class String
350
461
  set_self_value self.mixed_case preserve_prefixed_underscores: preserve_prefixed_underscores
351
462
  end
352
463
 
353
- # Checks if the string is a valid mixed case (without special characters!)
464
+ # Check if the string is a valid mixed case (without special characters!)
354
465
  #
355
466
  # @return [Boolean]
356
467
  def mixed_case?()
@@ -387,7 +498,7 @@ class String
387
498
  # CONSTANTIZE
388
499
  #----------------------------------------------------------------------------------------------------
389
500
 
390
- # Converts the string from any case
501
+ # Convert the string from any case
391
502
  # into pascal case and casts it into a constant
392
503
  #
393
504
  # @example conversion
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucky_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthäus J. N. Beyrle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler