lucky_case 1.0.4 → 1.1.0
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 +7 -2
- data/Rakefile +4 -0
- data/lib/lucky_case.rb +38 -0
- data/lib/lucky_case/string.rb +28 -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: eac6adfd588810a2859249ae38e7c67d0150c5887b8d77dfa696892ae1ea2a24
|
4
|
+
data.tar.gz: 5c4d028124cb29c76cbddf385a4ecadde25d0dc9f4e9e6bc2bf0a72825fd43f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb781175697d671389a9c2126e932178298c43272308615adf4f467a952212d3a95581a568d7a61714c2b7dc69f626c8a5f3fdea50337de0bc0996bfe645d2b1
|
7
|
+
data.tar.gz: abb0a8947521ec1146c1e4767a5a3dbcd6b63131185ffbb3682a495369e416be3e5b52ae8a28a1f42326b9af60c568fa205066658e15e94c55cb629dceb840c6
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
The lucky ruby gem to identify and convert strings from any letter case to another. Plus some extra functions.
|
4
4
|
|
5
|
+
I also created a javascript port named [lucky-case](https://github.com/magynhard/lucky-case).
|
6
|
+
|
5
7
|
Useful when working with conventions, where class names, method names and file names needs to be converted.
|
6
8
|
|
7
9
|
* Converters: Only characters, numbers, dashes and underlines are allowed inside a string.
|
@@ -51,6 +53,7 @@ LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
|
|
51
53
|
LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
|
52
54
|
LuckyCase.capital('example') # => 'Example'
|
53
55
|
LuckyCase.capitalize('example') # => 'Example'
|
56
|
+
LuckyCase.decapitalize('ExaMple') # => 'exaMple'
|
54
57
|
LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
|
55
58
|
LuckyCase.constantize('some_constant') # => SomeConstant
|
56
59
|
LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
|
@@ -79,6 +82,8 @@ LuckyCase.upper_case?('UPPER50984') # => true
|
|
79
82
|
LuckyCase.lower_case?('lower_cheese') # => true
|
80
83
|
LuckyCase.capital?('Some') # => true
|
81
84
|
LuckyCase.capitalized?('some') # => false
|
85
|
+
LuckyCase.decapitalized?('soMe') # => true
|
86
|
+
LuckyCase.not_capital?('Some') # => false
|
82
87
|
LuckyCase.valid_case_type?(:snake_case) # => true
|
83
88
|
LuckyCase.valid_case_type?(:apple_case) # => false
|
84
89
|
LuckyCase.valid_case_string?('validString') # => true
|
@@ -87,10 +92,10 @@ LuckyCase.valid_case_string?('1nV4lid$tring') # => false
|
|
87
92
|
|
88
93
|
### Approach 2: Monkey patch the string class
|
89
94
|
|
90
|
-
With monkey patching you can access the same methods (except deconstantize
|
95
|
+
With monkey patching you can access the same methods (except `#deconstantize`, `#valid_case_type?`) of LuckyCase directly from strings.
|
91
96
|
Additionally they provide versions with exclamation mark for direct manipulation.
|
92
97
|
|
93
|
-
Because the
|
98
|
+
Because the methods `#case` and `#cases` are so general and could lead to conflicts, they are called `#letter_case` and `#letter_cases` at strings.
|
94
99
|
|
95
100
|
```ruby
|
96
101
|
require 'lucky_case/string'
|
data/Rakefile
CHANGED
data/lib/lucky_case.rb
CHANGED
@@ -611,6 +611,44 @@ module LuckyCase
|
|
611
611
|
capital? string, skip_prefixed_underscores: skip_prefixed_underscores
|
612
612
|
end
|
613
613
|
|
614
|
+
# Convert the first character to lower case
|
615
|
+
#
|
616
|
+
# @param [String] string to convert
|
617
|
+
# @param [Boolean] skip_prefixed_underscores
|
618
|
+
# @return [String]
|
619
|
+
def self.decapitalize(string, skip_prefixed_underscores: false)
|
620
|
+
return string if string.empty?
|
621
|
+
s = if skip_prefixed_underscores
|
622
|
+
cut_underscores_at_start string
|
623
|
+
else
|
624
|
+
string
|
625
|
+
end
|
626
|
+
s = s[0].downcase + s[1..-1]
|
627
|
+
if skip_prefixed_underscores
|
628
|
+
underscores_at_start(string) + s
|
629
|
+
else
|
630
|
+
s
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
# Check if the strings first character is a lower letter
|
635
|
+
#
|
636
|
+
# @param [String] string to check
|
637
|
+
# @param [Boolean] skip_prefixed_underscores
|
638
|
+
# @return [Boolean]
|
639
|
+
def self.not_capital?(string, skip_prefixed_underscores: false)
|
640
|
+
decapitalized? string, skip_prefixed_underscores
|
641
|
+
end
|
642
|
+
|
643
|
+
# Check if the strings first character is a lower letter
|
644
|
+
#
|
645
|
+
# @param [String] string to check
|
646
|
+
# @param [Boolean] skip_prefixed_underscores
|
647
|
+
# @return [Boolean]
|
648
|
+
def self.decapitalized?(string, skip_prefixed_underscores: false)
|
649
|
+
!(capital? string, skip_prefixed_underscores)
|
650
|
+
end
|
651
|
+
|
614
652
|
#----------------------------------------------------------------------------------------------------
|
615
653
|
# MIXED CASE
|
616
654
|
#----------------------------------------------------------------------------------------------------
|
data/lib/lucky_case/string.rb
CHANGED
@@ -451,6 +451,34 @@ class String
|
|
451
451
|
self.capital? skip_prefixed_underscores: skip_prefixed_underscores
|
452
452
|
end
|
453
453
|
|
454
|
+
# Convert the first character to lower case
|
455
|
+
#
|
456
|
+
# @param [Boolean] skip_prefixed_underscores
|
457
|
+
# @return [String]
|
458
|
+
def decapitalize(skip_prefixed_underscores: false)
|
459
|
+
LuckyCase.decapitalize self, skip_prefixed_underscores: skip_prefixed_underscores
|
460
|
+
end
|
461
|
+
|
462
|
+
def decapitalize!(skip_prefixed_underscores: false)
|
463
|
+
set_self_value self.decapitalize skip_prefixed_underscores: skip_prefixed_underscores
|
464
|
+
end
|
465
|
+
|
466
|
+
# Check if the strings first character is a lower letter
|
467
|
+
#
|
468
|
+
# @param [Boolean] skip_prefixed_underscores
|
469
|
+
# @return [Boolean]
|
470
|
+
def decapitalized?(skip_prefixed_underscores: false)
|
471
|
+
LuckyCase.decapitalized? self, skip_prefixed_underscores: skip_prefixed_underscores
|
472
|
+
end
|
473
|
+
|
474
|
+
# Check if the strings first character is a lower letter
|
475
|
+
#
|
476
|
+
# @param [Boolean] skip_prefixed_underscores
|
477
|
+
# @return [Boolean]
|
478
|
+
def not_capital?(skip_prefixed_underscores: false)
|
479
|
+
self.decapitalized? skip_prefixed_underscores: skip_prefixed_underscores
|
480
|
+
end
|
481
|
+
|
454
482
|
#----------------------------------------------------------------------------------------------------
|
455
483
|
# MIXED CASE
|
456
484
|
#----------------------------------------------------------------------------------------------------
|
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: 1.0
|
4
|
+
version: 1.1.0
|
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:
|
11
|
+
date: 2021-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|