lucky_case 0.2.1 → 1.0.1
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 +4 -4
- data/README.md +22 -4
- data/lib/lucky_case.rb +77 -45
- data/lib/lucky_case/string.rb +40 -33
- data/lib/lucky_case/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f48f5e809c7ac7a21a5a42f3d98e0e074c297082d105f955d6770ad0b2ef02e
|
4
|
+
data.tar.gz: 020d6af3f21fd2aaa057dfe4024fa46234931c7fff4c8e163883a881848715b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb43b5b752f3c31a98dc1fd10c78f64d2dbb67e5a272796d738aac5d23c147887313164a9ff0a052fc634d8261b26bf9608f777d7cc71ddde5c57091bfdce2c
|
7
|
+
data.tar.gz: 4daa7ee01603efb6645e9dfe26897ee67ef8cd8e0389c006401269a1f95bf1dff3773efd608a1eb79577d7f7658c5fcff4c7f01f9eea0c86ff1ce0ca75810fc4
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ 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
|
-
###
|
28
|
+
### Approach 1: Using the static class
|
29
29
|
```ruby
|
30
30
|
require 'lucky_case'
|
31
31
|
|
@@ -42,8 +42,10 @@ LuckyCase.upper_word_case('PascalToUpperWord') # => 'PASCAL TO UPPER WOR
|
|
42
42
|
LuckyCase.capital_word_case('snake_to_capital_word') # => 'Snake To Capital Word'
|
43
43
|
LuckyCase.sentence_case('snake_to_sentence_case') # => 'Snake to sentence case'
|
44
44
|
LuckyCase.mixed_case('example_snake_string') # => 'Example-snake_STRING'
|
45
|
+
|
45
46
|
# converter by type
|
46
47
|
LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
|
48
|
+
|
47
49
|
# transformers
|
48
50
|
LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
|
49
51
|
LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
|
@@ -55,9 +57,11 @@ LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
|
|
55
57
|
LuckyCase.constantize('some/path_example/folder') # => Some::PathExample::Folder
|
56
58
|
LuckyCase.deconstantize(SomeConstant) # => 'some_constant'
|
57
59
|
LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
|
58
|
-
|
60
|
+
|
61
|
+
# identifiers
|
59
62
|
LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
|
60
63
|
LuckyCase.cases('validformultiple') # => [ :snake_case, :camel_case, :dash_case, :word_case ]
|
64
|
+
|
61
65
|
# checkers
|
62
66
|
LuckyCase.snake_case?('valid_snake_case') # => true
|
63
67
|
LuckyCase.upper_snake_case?('UPPER_SNAKE') # => true
|
@@ -75,13 +79,19 @@ LuckyCase.upper_case?('UPPER50984') # => true
|
|
75
79
|
LuckyCase.lower_case?('lower_cheese') # => true
|
76
80
|
LuckyCase.capital?('Some') # => true
|
77
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
|
78
86
|
```
|
79
87
|
|
80
|
-
### Monkey patch the string class
|
88
|
+
### Approach 2: Monkey patch the string class
|
81
89
|
|
82
|
-
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.
|
83
91
|
Additionally they provide versions with exclamation mark for direct manipulation.
|
84
92
|
|
93
|
+
Because the method #case is so general and could lead to conflicts, it is called #letter_case here.
|
94
|
+
|
85
95
|
```ruby
|
86
96
|
require 'lucky_case/string'
|
87
97
|
|
@@ -90,9 +100,17 @@ a = 'ExampleString'
|
|
90
100
|
a.pascal_case? # => true
|
91
101
|
a.snake_case # => 'example_string'
|
92
102
|
a # => 'ExampleString'
|
103
|
+
|
93
104
|
# string variable manipulation
|
94
105
|
a.snake_case! # => 'example_string'
|
95
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 ]
|
96
114
|
```
|
97
115
|
|
98
116
|
|
data/lib/lucky_case.rb
CHANGED
@@ -22,7 +22,7 @@ module LuckyCase
|
|
22
22
|
upper_word_case: /^[[:upper:]]{1}[[:upper:] 0-9]+$/,
|
23
23
|
capital_word_case: /^([[:upper:]][[:lower:]0-9]*\ |[0-9]+\ )*([[:upper:]][[:lower:]0-9]*)$/,
|
24
24
|
sentence_case: /^[[:upper:]]{1}[[:lower:] 0-9]+$/,
|
25
|
-
mixed_case: /^[[:upper:][:lower:]][[:upper:][:lower:]_\-0-9]*$/,
|
25
|
+
mixed_case: /^[[:upper:][:lower:]][[:upper:][:lower:]_\-0-9 ]*$/,
|
26
26
|
}
|
27
27
|
|
28
28
|
FORMATS = {
|
@@ -77,9 +77,9 @@ module LuckyCase
|
|
77
77
|
end
|
78
78
|
if matched_cases.empty?
|
79
79
|
nil
|
80
|
-
# reject mixed case if there are other matches
|
81
|
-
# because it would always be included if one other case matches
|
82
80
|
elsif matched_cases.size > 1
|
81
|
+
# reject :mixed_case if there are other matches
|
82
|
+
# because it would always be included if one other case matches
|
83
83
|
matched_cases.reject { |e| e == :mixed_case }
|
84
84
|
else
|
85
85
|
matched_cases
|
@@ -101,11 +101,31 @@ module LuckyCase
|
|
101
101
|
raise InvalidCaseError.new error_message
|
102
102
|
end
|
103
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] string
|
119
|
+
# @return [Boolean]
|
120
|
+
def self.valid_case_string?(string)
|
121
|
+
self.case(string) != nil
|
122
|
+
end
|
123
|
+
|
104
124
|
#----------------------------------------------------------------------------------------------------
|
105
125
|
# UPPER CASE
|
106
126
|
#----------------------------------------------------------------------------------------------------
|
107
127
|
|
108
|
-
#
|
128
|
+
# Convert all characters inside the string
|
109
129
|
# into upper case
|
110
130
|
#
|
111
131
|
# @example conversion
|
@@ -117,7 +137,7 @@ module LuckyCase
|
|
117
137
|
string.upcase
|
118
138
|
end
|
119
139
|
|
120
|
-
#
|
140
|
+
# Check if all characters inside the string are upper case
|
121
141
|
#
|
122
142
|
# @param [String] string to check
|
123
143
|
# @return [Boolean]
|
@@ -129,7 +149,7 @@ module LuckyCase
|
|
129
149
|
# LOWER CASE
|
130
150
|
#----------------------------------------------------------------------------------------------------
|
131
151
|
|
132
|
-
#
|
152
|
+
# Convert all characters inside the string
|
133
153
|
# into lower case
|
134
154
|
#
|
135
155
|
# @example conversion
|
@@ -141,7 +161,7 @@ module LuckyCase
|
|
141
161
|
string.downcase
|
142
162
|
end
|
143
163
|
|
144
|
-
#
|
164
|
+
# Check if all characters inside the string are lower case
|
145
165
|
#
|
146
166
|
# @param [String] string to check
|
147
167
|
# @return [Boolean]
|
@@ -153,7 +173,7 @@ module LuckyCase
|
|
153
173
|
# SNAKE CASE
|
154
174
|
#----------------------------------------------------------------------------------------------------
|
155
175
|
|
156
|
-
#
|
176
|
+
# Convert the given string from any case
|
157
177
|
# into snake case
|
158
178
|
#
|
159
179
|
# @example conversion
|
@@ -172,7 +192,7 @@ module LuckyCase
|
|
172
192
|
end
|
173
193
|
end
|
174
194
|
|
175
|
-
#
|
195
|
+
# Check if the string is snake case
|
176
196
|
#
|
177
197
|
# @param [String] string to check
|
178
198
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -186,7 +206,7 @@ module LuckyCase
|
|
186
206
|
_case_match? s, :snake_case
|
187
207
|
end
|
188
208
|
|
189
|
-
#
|
209
|
+
# Convert the given string from any case
|
190
210
|
# into upper snake case
|
191
211
|
#
|
192
212
|
# @example conversion
|
@@ -205,7 +225,7 @@ module LuckyCase
|
|
205
225
|
end
|
206
226
|
end
|
207
227
|
|
208
|
-
#
|
228
|
+
# Check if the string is upper snake case
|
209
229
|
#
|
210
230
|
# @param [String] string to check
|
211
231
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -223,7 +243,7 @@ module LuckyCase
|
|
223
243
|
# PASCAL CASE
|
224
244
|
#----------------------------------------------------------------------------------------------------
|
225
245
|
|
226
|
-
#
|
246
|
+
# Convert the given string from any case
|
227
247
|
# into pascal case
|
228
248
|
#
|
229
249
|
# @example conversion
|
@@ -242,7 +262,7 @@ module LuckyCase
|
|
242
262
|
end
|
243
263
|
end
|
244
264
|
|
245
|
-
#
|
265
|
+
# Check if the string is upper pascal case
|
246
266
|
#
|
247
267
|
# @param [String] string to check
|
248
268
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -260,7 +280,7 @@ module LuckyCase
|
|
260
280
|
# CAMEL CASE
|
261
281
|
#----------------------------------------------------------------------------------------------------
|
262
282
|
|
263
|
-
#
|
283
|
+
# Convert the given string from any case
|
264
284
|
# into camel case
|
265
285
|
#
|
266
286
|
# @example conversion
|
@@ -279,7 +299,7 @@ module LuckyCase
|
|
279
299
|
end
|
280
300
|
end
|
281
301
|
|
282
|
-
#
|
302
|
+
# Check if the string is camel case
|
283
303
|
#
|
284
304
|
# @param [String] string to check
|
285
305
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -297,7 +317,7 @@ module LuckyCase
|
|
297
317
|
# DASH CASE
|
298
318
|
#----------------------------------------------------------------------------------------------------
|
299
319
|
|
300
|
-
#
|
320
|
+
# Convert the given string from any case
|
301
321
|
# into dash case
|
302
322
|
#
|
303
323
|
# @example conversion
|
@@ -316,7 +336,7 @@ module LuckyCase
|
|
316
336
|
end
|
317
337
|
end
|
318
338
|
|
319
|
-
#
|
339
|
+
# Check if the string is dash case
|
320
340
|
#
|
321
341
|
# @param [String] string to check
|
322
342
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -330,7 +350,7 @@ module LuckyCase
|
|
330
350
|
_case_match? s, :dash_case
|
331
351
|
end
|
332
352
|
|
333
|
-
#
|
353
|
+
# Convert the given string from any case
|
334
354
|
# into upper dash case
|
335
355
|
#
|
336
356
|
# @example conversion
|
@@ -344,7 +364,7 @@ module LuckyCase
|
|
344
364
|
upper_case s
|
345
365
|
end
|
346
366
|
|
347
|
-
#
|
367
|
+
# Check if the string is upper dash case
|
348
368
|
#
|
349
369
|
# @param [String] string to check
|
350
370
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -362,7 +382,7 @@ module LuckyCase
|
|
362
382
|
# TRAIN CASE
|
363
383
|
#----------------------------------------------------------------------------------------------------
|
364
384
|
|
365
|
-
#
|
385
|
+
# Convert the given string from any case
|
366
386
|
# into train case
|
367
387
|
#
|
368
388
|
# @example conversion
|
@@ -381,7 +401,7 @@ module LuckyCase
|
|
381
401
|
end
|
382
402
|
end
|
383
403
|
|
384
|
-
#
|
404
|
+
# Check if the string is train case
|
385
405
|
#
|
386
406
|
# @param [String] string to check
|
387
407
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -399,7 +419,7 @@ module LuckyCase
|
|
399
419
|
# WORD CASE
|
400
420
|
#----------------------------------------------------------------------------------------------------
|
401
421
|
|
402
|
-
#
|
422
|
+
# Convert the given string from any case
|
403
423
|
# into word case
|
404
424
|
#
|
405
425
|
# @example conversion
|
@@ -418,7 +438,7 @@ module LuckyCase
|
|
418
438
|
end
|
419
439
|
end
|
420
440
|
|
421
|
-
#
|
441
|
+
# Check if the string is word case
|
422
442
|
#
|
423
443
|
# @param [String] string to check
|
424
444
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -432,7 +452,7 @@ module LuckyCase
|
|
432
452
|
_case_match? s, :word_case
|
433
453
|
end
|
434
454
|
|
435
|
-
#
|
455
|
+
# Convert the given string from any case
|
436
456
|
# into upper word case
|
437
457
|
#
|
438
458
|
# @example conversion
|
@@ -451,7 +471,7 @@ module LuckyCase
|
|
451
471
|
end
|
452
472
|
end
|
453
473
|
|
454
|
-
#
|
474
|
+
# Check if the string is upper word case
|
455
475
|
#
|
456
476
|
# @param [String] string to check
|
457
477
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -465,7 +485,7 @@ module LuckyCase
|
|
465
485
|
_case_match? s, :upper_word_case
|
466
486
|
end
|
467
487
|
|
468
|
-
#
|
488
|
+
# Convert the given string from any case
|
469
489
|
# into capital word case
|
470
490
|
#
|
471
491
|
# @example conversion
|
@@ -484,7 +504,7 @@ module LuckyCase
|
|
484
504
|
end
|
485
505
|
end
|
486
506
|
|
487
|
-
#
|
507
|
+
# Check if the string is capital word case
|
488
508
|
#
|
489
509
|
# @param [String] string to check
|
490
510
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -502,7 +522,7 @@ module LuckyCase
|
|
502
522
|
# SENTENCE CASE
|
503
523
|
#----------------------------------------------------------------------------------------------------
|
504
524
|
|
505
|
-
#
|
525
|
+
# Convert the given string from any case
|
506
526
|
# into sentence case
|
507
527
|
#
|
508
528
|
# @example conversion
|
@@ -521,7 +541,7 @@ module LuckyCase
|
|
521
541
|
end
|
522
542
|
end
|
523
543
|
|
524
|
-
#
|
544
|
+
# Check if the string is sentence case
|
525
545
|
#
|
526
546
|
# @param [String] string to check
|
527
547
|
# @param [Boolean] allow_prefixed_underscores
|
@@ -539,7 +559,7 @@ module LuckyCase
|
|
539
559
|
# CAPITALIZE
|
540
560
|
#----------------------------------------------------------------------------------------------------
|
541
561
|
|
542
|
-
#
|
562
|
+
# Convert the first character to capital
|
543
563
|
#
|
544
564
|
# @param [String] string to convert
|
545
565
|
# @param [Boolean] skip_prefixed_underscores
|
@@ -559,7 +579,7 @@ module LuckyCase
|
|
559
579
|
end
|
560
580
|
end
|
561
581
|
|
562
|
-
#
|
582
|
+
# Convert the first character to capital
|
563
583
|
#
|
564
584
|
# @param [String] string to convert
|
565
585
|
# @param [Boolean] skip_prefixed_underscores
|
@@ -568,7 +588,7 @@ module LuckyCase
|
|
568
588
|
capital string, skip_prefixed_underscores: skip_prefixed_underscores
|
569
589
|
end
|
570
590
|
|
571
|
-
#
|
591
|
+
# Check if the strings first character is a capital letter
|
572
592
|
#
|
573
593
|
# @param [String] string to check
|
574
594
|
# @param [Boolean] skip_prefixed_underscores
|
@@ -582,7 +602,7 @@ module LuckyCase
|
|
582
602
|
_case_match? s, :capital
|
583
603
|
end
|
584
604
|
|
585
|
-
#
|
605
|
+
# Check if the strings first character is a capital letter
|
586
606
|
#
|
587
607
|
# @param [String] string to check
|
588
608
|
# @param [Boolean] skip_prefixed_underscores
|
@@ -595,8 +615,10 @@ module LuckyCase
|
|
595
615
|
# MIXED CASE
|
596
616
|
#----------------------------------------------------------------------------------------------------
|
597
617
|
|
598
|
-
#
|
599
|
-
# into mixed case
|
618
|
+
# Convert the given string from any case
|
619
|
+
# into mixed case.
|
620
|
+
#
|
621
|
+
# The new string is ensured to be different from the input.
|
600
622
|
#
|
601
623
|
# @example conversion
|
602
624
|
# 'this-isAnExample_string' => 'This-Is_anExample-string'
|
@@ -606,9 +628,14 @@ module LuckyCase
|
|
606
628
|
# @return [String]
|
607
629
|
def self.mixed_case(string, preserve_prefixed_underscores: true)
|
608
630
|
a = split_case_string string
|
609
|
-
converted =
|
610
|
-
|
611
|
-
converted
|
631
|
+
converted = nil
|
632
|
+
loop do
|
633
|
+
converted = ''
|
634
|
+
a.each do |part|
|
635
|
+
converted += self.convert_case part, CASES.keys.sample, preserve_prefixed_underscores: preserve_prefixed_underscores
|
636
|
+
end
|
637
|
+
converted = self.convert_case converted, CASES.keys.sample, preserve_prefixed_underscores: preserve_prefixed_underscores
|
638
|
+
break if converted != string && underscores_at_start(string) + converted != string
|
612
639
|
end
|
613
640
|
if preserve_prefixed_underscores
|
614
641
|
underscores_at_start(string) + converted
|
@@ -617,12 +644,17 @@ module LuckyCase
|
|
617
644
|
end
|
618
645
|
end
|
619
646
|
|
620
|
-
#
|
647
|
+
# Check if the string is a valid mixed case (without special characters!)
|
621
648
|
#
|
622
649
|
# @param [String] string to check
|
623
650
|
# @return [Boolean]
|
624
|
-
def self.mixed_case?(string)
|
625
|
-
|
651
|
+
def self.mixed_case?(string, allow_prefixed_underscores: true)
|
652
|
+
s = if allow_prefixed_underscores
|
653
|
+
cut_underscores_at_start string
|
654
|
+
else
|
655
|
+
string
|
656
|
+
end
|
657
|
+
_case_match? s, :mixed_case
|
626
658
|
end
|
627
659
|
|
628
660
|
#----------------------------------------------------------------------------------------------------
|
@@ -672,7 +704,7 @@ module LuckyCase
|
|
672
704
|
# CONSTANTIZE
|
673
705
|
#----------------------------------------------------------------------------------------------------
|
674
706
|
|
675
|
-
#
|
707
|
+
# Convert the string from any case
|
676
708
|
# into pascal case and casts it into a constant
|
677
709
|
#
|
678
710
|
# @example conversion
|
@@ -782,10 +814,10 @@ module LuckyCase
|
|
782
814
|
# Check if the given case matches the string
|
783
815
|
#
|
784
816
|
# @param [String] string
|
785
|
-
# @param [Symbol,String]
|
817
|
+
# @param [Symbol,String] case_type
|
786
818
|
# @return [Boolean]
|
787
|
-
def self._case_match?(string,
|
788
|
-
!!(string =~ CASES[
|
819
|
+
def self._case_match?(string, case_type)
|
820
|
+
!!(string =~ CASES[case_type.to_sym])
|
789
821
|
end
|
790
822
|
|
791
823
|
#----------------------------------------------------------------------------------------------------
|
data/lib/lucky_case/string.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
288
|
+
# Check if the string is train case
|
282
289
|
#
|
283
290
|
# @param [Boolean] allow_prefixed_underscores
|
284
291
|
# @return [Boolean]
|
@@ -290,7 +297,7 @@ class String
|
|
290
297
|
# WORD CASE
|
291
298
|
#----------------------------------------------------------------------------------------------------
|
292
299
|
|
293
|
-
#
|
300
|
+
# Convert the given string from any case
|
294
301
|
# into word case
|
295
302
|
#
|
296
303
|
# @example conversion
|
@@ -306,7 +313,7 @@ class String
|
|
306
313
|
set_self_value self.word_case preserve_prefixed_underscores: preserve_prefixed_underscores
|
307
314
|
end
|
308
315
|
|
309
|
-
#
|
316
|
+
# Check if the string is word case
|
310
317
|
#
|
311
318
|
# @param [Boolean] allow_prefixed_underscores
|
312
319
|
# @return [Boolean]
|
@@ -314,7 +321,7 @@ class String
|
|
314
321
|
LuckyCase.word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
|
315
322
|
end
|
316
323
|
|
317
|
-
#
|
324
|
+
# Convert the given string from any case
|
318
325
|
# into upper word case
|
319
326
|
#
|
320
327
|
# @example conversion
|
@@ -330,7 +337,7 @@ class String
|
|
330
337
|
set_self_value self.upper_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
|
331
338
|
end
|
332
339
|
|
333
|
-
#
|
340
|
+
# Check if the string is upper word case
|
334
341
|
#
|
335
342
|
# @param [Boolean] allow_prefixed_underscores
|
336
343
|
# @return [Boolean]
|
@@ -338,7 +345,7 @@ class String
|
|
338
345
|
LuckyCase.upper_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
|
339
346
|
end
|
340
347
|
|
341
|
-
#
|
348
|
+
# Convert the given string from any case
|
342
349
|
# into capital word case
|
343
350
|
#
|
344
351
|
# @example conversion
|
@@ -354,7 +361,7 @@ class String
|
|
354
361
|
set_self_value self.capital_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
|
355
362
|
end
|
356
363
|
|
357
|
-
#
|
364
|
+
# Check if the string is capital word case
|
358
365
|
#
|
359
366
|
# @param [Boolean] allow_prefixed_underscores
|
360
367
|
# @return [Boolean]
|
@@ -366,7 +373,7 @@ class String
|
|
366
373
|
# SENTENCE CASE
|
367
374
|
#----------------------------------------------------------------------------------------------------
|
368
375
|
|
369
|
-
#
|
376
|
+
# Convert the given string from any case
|
370
377
|
# into sentence case
|
371
378
|
#
|
372
379
|
# @example conversion
|
@@ -382,7 +389,7 @@ class String
|
|
382
389
|
set_self_value self.sentence_case preserve_prefixed_underscores: preserve_prefixed_underscores
|
383
390
|
end
|
384
391
|
|
385
|
-
#
|
392
|
+
# Check if the string is sentence case
|
386
393
|
#
|
387
394
|
# @param [Boolean] allow_prefixed_underscores
|
388
395
|
# @return [Boolean]
|
@@ -394,7 +401,7 @@ class String
|
|
394
401
|
# CAPITALIZE
|
395
402
|
#----------------------------------------------------------------------------------------------------
|
396
403
|
|
397
|
-
#
|
404
|
+
# Convert the first character to capital
|
398
405
|
#
|
399
406
|
# @param [Boolean] skip_prefixed_underscores
|
400
407
|
# @return [String]
|
@@ -402,7 +409,7 @@ class String
|
|
402
409
|
LuckyCase.capitalize self, skip_prefixed_underscores: skip_prefixed_underscores
|
403
410
|
end
|
404
411
|
|
405
|
-
#
|
412
|
+
# Convert the first character to capital
|
406
413
|
#
|
407
414
|
# @param [Boolean] skip_prefixed_underscores
|
408
415
|
# @return [String]
|
@@ -418,7 +425,7 @@ class String
|
|
418
425
|
self.capital! skip_prefixed_underscores: skip_prefixed_underscores
|
419
426
|
end
|
420
427
|
|
421
|
-
#
|
428
|
+
# Check if the strings first character is a capital letter
|
422
429
|
#
|
423
430
|
# @param [Boolean] skip_prefixed_underscores
|
424
431
|
# @return [Boolean]
|
@@ -426,7 +433,7 @@ class String
|
|
426
433
|
LuckyCase.capital? self, skip_prefixed_underscores: skip_prefixed_underscores
|
427
434
|
end
|
428
435
|
|
429
|
-
#
|
436
|
+
# Check if the strings first character is a capital letter
|
430
437
|
#
|
431
438
|
# @param [Boolean] skip_prefixed_underscores
|
432
439
|
# @return [Boolean]
|
@@ -438,7 +445,7 @@ class String
|
|
438
445
|
# MIXED CASE
|
439
446
|
#----------------------------------------------------------------------------------------------------
|
440
447
|
|
441
|
-
#
|
448
|
+
# Convert the given string from any case
|
442
449
|
# into mixed case
|
443
450
|
#
|
444
451
|
# @example conversion
|
@@ -454,7 +461,7 @@ class String
|
|
454
461
|
set_self_value self.mixed_case preserve_prefixed_underscores: preserve_prefixed_underscores
|
455
462
|
end
|
456
463
|
|
457
|
-
#
|
464
|
+
# Check if the string is a valid mixed case (without special characters!)
|
458
465
|
#
|
459
466
|
# @return [Boolean]
|
460
467
|
def mixed_case?()
|
@@ -491,7 +498,7 @@ class String
|
|
491
498
|
# CONSTANTIZE
|
492
499
|
#----------------------------------------------------------------------------------------------------
|
493
500
|
|
494
|
-
#
|
501
|
+
# Convert the string from any case
|
495
502
|
# into pascal case and casts it into a constant
|
496
503
|
#
|
497
504
|
# @example conversion
|
data/lib/lucky_case/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|