lucky_case 0.2.3 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfe36f3ecf272ce46d7350964f6396949e54b49544e2d4a886b27cba698acedd
4
- data.tar.gz: 99e2745316e403bd0c1258bfc5db260da120b3215f224d38efee03a5bcc46392
3
+ metadata.gz: 4d91221703f4cca3ccf7e9e7714faf4ec6f952b0a991bfc3b7d10aacdc561e5c
4
+ data.tar.gz: 35de64aa46273435da38b1f9481e5afa114f7784fe0e4d19fc74f4fab94a02e2
5
5
  SHA512:
6
- metadata.gz: 704d45b0cd6df44c2097b467759a0a4ec58d42b0fdbeed78b3cf11f8012b68aae9fd9beb2bb23fa25224338d876e93daf1001b7616491665224c6ebe45dcdbd1
7
- data.tar.gz: 60d487477cf8d5515ec135a370aaa97b78665ad6ec060f63a29e0190858ea7ddc5eb09dd1642d15da2ff3bc03c378878e41e2a228649bb646ecd5dbb70f901df
6
+ metadata.gz: 93190ee833624b31bc31343fdfc8a48203e8f36053681c1c1a9501385a6008ca4adb77e6f8a38681f4eaf8b022a5dc2a6315f6eea34a51ea9fbc02aa270bf9b0
7
+ data.tar.gz: bc65c176a899d81cefe33c46fc2dc8a6767edefbd9a4f9bbc1604eb577e73a035c4bb428afc1f1c40e3726edef05d5ea05100d180d6848e32a94b7c5a7daef85
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) # => 'some/pathExample/folder'
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 is so general and could lead to conflicts, it is called #letter_case here.
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'
@@ -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
@@ -115,12 +115,12 @@ module LuckyCase
115
115
 
116
116
  # Check if the string matches any of the available cases
117
117
  #
118
- # @param [String] case_type
118
+ # @param [String] string
119
119
  # @return [Boolean]
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
- a.each do |part|
631
- converted += self.send random_case, part
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
- _case_match? string, :mixed_case
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
@@ -802,10 +814,10 @@ module LuckyCase
802
814
  # Check if the given case matches the string
803
815
  #
804
816
  # @param [String] string
805
- # @param [Symbol,String] case_to_match
817
+ # @param [Symbol,String] case_type
806
818
  # @return [Boolean]
807
- def self._case_match?(string, case_to_match)
808
- !!(string =~ CASES[case_to_match.to_sym])
819
+ def self._case_match?(string, case_type)
820
+ !!(string =~ CASES[case_type.to_sym])
809
821
  end
810
822
 
811
823
  #----------------------------------------------------------------------------------------------------
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '1.0.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.2.3
4
+ version: 1.0.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-14 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler