lucky_case 0.2.4 → 1.0.0

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: 44cb7edfeae8e3d330f2709c441e2ed38b6b29c3aeec8039831606bd5f9489e6
4
- data.tar.gz: df3a7a195ed45ca1b1a66571f6f5616403fd7e38dff9806d558c99ac72556e5a
3
+ metadata.gz: c7c4dc263bc163972145a81df6aee8c9f95326618965c5fae6f499be6d90aad7
4
+ data.tar.gz: 28397c3898961a0651a518ecfcf22750f54646433b032cb1a61148e0953bdea8
5
5
  SHA512:
6
- metadata.gz: 3785b9b371fed6dd88db71b6dd89e01ccd540c54a4f00b04f7b5fc29e9fd6ea38d6b5eb6fc8c52a4a826e5903edb3096a514aff87b5a812ff6cb3d313c49abcf
7
- data.tar.gz: e8677f3b9ea32606c41c8b60a30730cc303f206c644c386129720d154705d7e4dda99a982ef0f027b916682e48ea4d4567d0aee0b883c7f7657405ab8226717f
6
+ metadata.gz: 3bee15287a4859b58818ba57c602afe70623c8020177b6af654f08059325f64fc03cce898d7ae97d7d33a6acdf9ee81afd47a5251049f05e25bffb51125a4bf6
7
+ data.tar.gz: 68ffb0cc620c65ce3bca6f0ec5c14d582ad01cab8477be6afdfafa67728888989b15f28bc851c409c622f86fd0aab2cbc5520397b221b3845fdd2589b6bd8214
@@ -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
- 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.send CASES.keys.sample, part
636
+ end
637
+ converted = self.send CASES.keys.sample, converted
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
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '0.2.4'.freeze
2
+ VERSION = '1.0.0'.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.4
4
+ version: 1.0.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: 2020-11-23 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