lucky_case 1.0.4 → 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: 127f2c04780cc216f3bfa6c606ecd720179bb70ec45973f2014eb5597643bb18
4
- data.tar.gz: d0f7b9a6eb16c83101a6a5dbbdcf6a7d11b645107a163f6e9fd4ea78a96fa8ed
3
+ metadata.gz: eac6adfd588810a2859249ae38e7c67d0150c5887b8d77dfa696892ae1ea2a24
4
+ data.tar.gz: 5c4d028124cb29c76cbddf385a4ecadde25d0dc9f4e9e6bc2bf0a72825fd43f1
5
5
  SHA512:
6
- metadata.gz: 50b70d0e7b6d9ed1c3d74c268e4a8e770738b77d0992ddde1a887d3a556d1ef0bcaff45132ecd12577db457824f909b92ef544e2c28293e313809d113e3f8b3d
7
- data.tar.gz: 118b3cb70f084a9121e87ba015de64a6b5e9f8b616fa52b011478b584318d81152ec72b9163ea88b9e704c071c69220f1ccf28a5a46bf987d2c0ba82ba91d6ec
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, 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 and #cases are so general and could lead to conflicts, they are called #letter_case and #letter_cases at strings.
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
  #----------------------------------------------------------------------------------------------------
@@ -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
  #----------------------------------------------------------------------------------------------------
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '1.0.4'.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.4
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-12-05 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