lucky_case 1.0.0 → 1.1.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: c7c4dc263bc163972145a81df6aee8c9f95326618965c5fae6f499be6d90aad7
4
- data.tar.gz: 28397c3898961a0651a518ecfcf22750f54646433b032cb1a61148e0953bdea8
3
+ metadata.gz: eac6adfd588810a2859249ae38e7c67d0150c5887b8d77dfa696892ae1ea2a24
4
+ data.tar.gz: 5c4d028124cb29c76cbddf385a4ecadde25d0dc9f4e9e6bc2bf0a72825fd43f1
5
5
  SHA512:
6
- metadata.gz: 3bee15287a4859b58818ba57c602afe70623c8020177b6af654f08059325f64fc03cce898d7ae97d7d33a6acdf9ee81afd47a5251049f05e25bffb51125a4bf6
7
- data.tar.gz: 68ffb0cc620c65ce3bca6f0ec5c14d582ad01cab8477be6afdfafa67728888989b15f28bc851c409c622f86fd0aab2cbc5520397b221b3845fdd2589b6bd8214
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.
@@ -49,14 +51,15 @@ LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
49
51
  # transformers
50
52
  LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
51
53
  LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
52
- LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
53
54
  LuckyCase.capital('example') # => 'Example'
54
55
  LuckyCase.capitalize('example') # => 'Example'
56
+ LuckyCase.decapitalize('ExaMple') # => 'exaMple'
57
+ LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
55
58
  LuckyCase.constantize('some_constant') # => SomeConstant
56
59
  LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
57
60
  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'
61
+ LuckyCase.deconstantize(SomeConstant) # => 'some_constant' // default case_type: :snake_case
62
+ LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
60
63
 
61
64
  # identifiers
62
65
  LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
@@ -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, valid_case_type?) of LuckyCase directly from strings.
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 method #case is so general and could lead to conflicts, it is called #letter_case here.
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
@@ -8,4 +8,8 @@ task :default do
8
8
  system 'rake --tasks'
9
9
  end
10
10
 
11
+ task :test do
12
+ system 'rspec'
13
+ end
14
+
11
15
  RSpec::Core::RakeTask.new(:spec)
@@ -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
  #----------------------------------------------------------------------------------------------------
@@ -632,9 +670,9 @@ module LuckyCase
632
670
  loop do
633
671
  converted = ''
634
672
  a.each do |part|
635
- converted += self.send CASES.keys.sample, part
673
+ converted += self.convert_case part, CASES.keys.sample, preserve_prefixed_underscores: preserve_prefixed_underscores
636
674
  end
637
- converted = self.send CASES.keys.sample, converted
675
+ converted = self.convert_case converted, CASES.keys.sample, preserve_prefixed_underscores: preserve_prefixed_underscores
638
676
  break if converted != string && underscores_at_start(string) + converted != string
639
677
  end
640
678
  if preserve_prefixed_underscores
@@ -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
@@ -441,6 +451,34 @@ class String
441
451
  self.capital? skip_prefixed_underscores: skip_prefixed_underscores
442
452
  end
443
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
+
444
482
  #----------------------------------------------------------------------------------------------------
445
483
  # MIXED CASE
446
484
  #----------------------------------------------------------------------------------------------------
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.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: 1.0.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: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler