lucky_case 0.2.4 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/lucky_case.rb +20 -8
- data/lib/lucky_case/string.rb +10 -0
- 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: 127f2c04780cc216f3bfa6c606ecd720179bb70ec45973f2014eb5597643bb18
|
4
|
+
data.tar.gz: d0f7b9a6eb16c83101a6a5dbbdcf6a7d11b645107a163f6e9fd4ea78a96fa8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b70d0e7b6d9ed1c3d74c268e4a8e770738b77d0992ddde1a887d3a556d1ef0bcaff45132ecd12577db457824f909b92ef544e2c28293e313809d113e3f8b3d
|
7
|
+
data.tar.gz: 118b3cb70f084a9121e87ba015de64a6b5e9f8b616fa52b011478b584318d81152ec72b9163ea88b9e704c071c69220f1ccf28a5a46bf987d2c0ba82ba91d6ec
|
data/README.md
CHANGED
@@ -49,14 +49,14 @@ LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
|
|
49
49
|
# transformers
|
50
50
|
LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
|
51
51
|
LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
|
52
|
-
LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
|
53
52
|
LuckyCase.capital('example') # => 'Example'
|
54
53
|
LuckyCase.capitalize('example') # => 'Example'
|
54
|
+
LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
|
55
55
|
LuckyCase.constantize('some_constant') # => SomeConstant
|
56
56
|
LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
|
57
57
|
LuckyCase.constantize('some/path_example/folder') # => Some::PathExample::Folder
|
58
|
-
LuckyCase.deconstantize(SomeConstant) # => 'some_constant'
|
59
|
-
LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case)
|
58
|
+
LuckyCase.deconstantize(SomeConstant) # => 'some_constant' // default case_type: :snake_case
|
59
|
+
LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
|
60
60
|
|
61
61
|
# identifiers
|
62
62
|
LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
|
@@ -90,7 +90,7 @@ LuckyCase.valid_case_string?('1nV4lid$tring') # => false
|
|
90
90
|
With monkey patching you can access the same methods (except deconstantize, valid_case_type?) of LuckyCase directly from strings.
|
91
91
|
Additionally they provide versions with exclamation mark for direct manipulation.
|
92
92
|
|
93
|
-
Because the method #case
|
93
|
+
Because the method #case and #cases are so general and could lead to conflicts, they are called #letter_case and #letter_cases at strings.
|
94
94
|
|
95
95
|
```ruby
|
96
96
|
require 'lucky_case/string'
|
data/lib/lucky_case.rb
CHANGED
@@ -120,7 +120,7 @@ module LuckyCase
|
|
120
120
|
def self.valid_case_string?(string)
|
121
121
|
self.case(string) != nil
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
#----------------------------------------------------------------------------------------------------
|
125
125
|
# UPPER CASE
|
126
126
|
#----------------------------------------------------------------------------------------------------
|
@@ -616,7 +616,9 @@ module LuckyCase
|
|
616
616
|
#----------------------------------------------------------------------------------------------------
|
617
617
|
|
618
618
|
# Convert the given string from any case
|
619
|
-
# into mixed case
|
619
|
+
# into mixed case.
|
620
|
+
#
|
621
|
+
# The new string is ensured to be different from the input.
|
620
622
|
#
|
621
623
|
# @example conversion
|
622
624
|
# 'this-isAnExample_string' => 'This-Is_anExample-string'
|
@@ -626,9 +628,14 @@ module LuckyCase
|
|
626
628
|
# @return [String]
|
627
629
|
def self.mixed_case(string, preserve_prefixed_underscores: true)
|
628
630
|
a = split_case_string string
|
629
|
-
converted =
|
630
|
-
|
631
|
-
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
|
632
639
|
end
|
633
640
|
if preserve_prefixed_underscores
|
634
641
|
underscores_at_start(string) + converted
|
@@ -641,8 +648,13 @@ module LuckyCase
|
|
641
648
|
#
|
642
649
|
# @param [String] string to check
|
643
650
|
# @return [Boolean]
|
644
|
-
def self.mixed_case?(string)
|
645
|
-
|
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
|
646
658
|
end
|
647
659
|
|
648
660
|
#----------------------------------------------------------------------------------------------------
|
@@ -750,7 +762,7 @@ module LuckyCase
|
|
750
762
|
#----------------------------------------------------------------------------------------------------
|
751
763
|
# HELPERS
|
752
764
|
#----------------------------------------------------------------------------------------------------
|
753
|
-
|
765
|
+
|
754
766
|
# Return string without underscores at the start
|
755
767
|
#
|
756
768
|
# @param [String] string
|
data/lib/lucky_case/string.rb
CHANGED
@@ -21,6 +21,11 @@ class String
|
|
21
21
|
#
|
22
22
|
# @param [Boolean] allow_prefixed_underscores
|
23
23
|
# @return [Symbol,nil] symbol of type, nil if no match
|
24
|
+
def letter_case(allow_prefixed_underscores: true)
|
25
|
+
LuckyCase.case self, allow_prefixed_underscores: allow_prefixed_underscores
|
26
|
+
end
|
27
|
+
|
28
|
+
# easter egg version of #letter_case
|
24
29
|
def lucky_case(allow_prefixed_underscores: true)
|
25
30
|
LuckyCase.case self, allow_prefixed_underscores: allow_prefixed_underscores
|
26
31
|
end
|
@@ -29,6 +34,11 @@ class String
|
|
29
34
|
#
|
30
35
|
# @param [Boolean] allow_prefixed_underscores
|
31
36
|
# @return [Array<Symbol>,nil] symbols of types, nil if no one matches
|
37
|
+
def letter_cases(allow_prefixed_underscores: true)
|
38
|
+
LuckyCase.cases self, allow_prefixed_underscores: allow_prefixed_underscores
|
39
|
+
end
|
40
|
+
|
41
|
+
# easter egg version of #letter_cases
|
32
42
|
def lucky_cases(allow_prefixed_underscores: true)
|
33
43
|
LuckyCase.cases self, allow_prefixed_underscores: allow_prefixed_underscores
|
34
44
|
end
|
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.4
|
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-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|