README.md in lucky_case-0.2.2 vs README.md in lucky_case-0.2.3
- old
+ new
@@ -23,11 +23,11 @@
<a name="usage"></a>
## Usage
You can either use the static LuckyCase class with its method or optionally monkey patch the String class.
-### Use the static class only
+### Approach 1: Using the static class
```ruby
require 'lucky_case'
# converters
LuckyCase.snake_case('PascalToSnake') # => 'pascal_to_snake'
@@ -40,12 +40,14 @@
LuckyCase.word_case('PascalToWordCase') # => 'pascal to word case'
LuckyCase.upper_word_case('PascalToUpperWord') # => 'PASCAL TO UPPER WORD'
LuckyCase.capital_word_case('snake_to_capital_word') # => 'Snake To Capital Word'
LuckyCase.sentence_case('snake_to_sentence_case') # => 'Snake to sentence case'
LuckyCase.mixed_case('example_snake_string') # => 'Example-snake_STRING'
+
# converter by type
LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
+
# transformers
LuckyCase.lower_case('Some_FuckingShit') # => 'some_fuckingshit'
LuckyCase.upper_case('Some_FuckingShit') # => 'SOME_FUCKINGSHIT'
LuckyCase.swap_case('SomeSwappy_Case-Example') # => 'sOMEsWAPPY-cASE_eXAMPLE'
LuckyCase.capital('example') # => 'Example'
@@ -53,13 +55,15 @@
LuckyCase.constantize('some_constant') # => SomeConstant
LuckyCase.constantize('SOME_CONSTANT') # => SomeConstant
LuckyCase.constantize('some/path_example/folder') # => Some::PathExample::Folder
LuckyCase.deconstantize(SomeConstant) # => 'some_constant'
LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
+
# identifiers
LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
LuckyCase.cases('validformultiple') # => [ :snake_case, :camel_case, :dash_case, :word_case ]
+
# checkers
LuckyCase.snake_case?('valid_snake_case') # => true
LuckyCase.upper_snake_case?('UPPER_SNAKE') # => true
LuckyCase.pascal_case?('PascalCase') # => true
LuckyCase.camel_case?('camelCase') # => true
@@ -79,11 +83,11 @@
LuckyCase.valid_case_type?(:apple_case) # => false
LuckyCase.valid_case_string?('validString') # => true
LuckyCase.valid_case_string?('1nV4lid$tring') # => false
```
-### Monkey patch the string class
+### Approach 2: Monkey patch the string class
With monkey patching you can access the same methods (except deconstantize, valid_case_type?) of LuckyCase directly from strings.
Additionally they provide versions with exclamation mark for direct manipulation.
Because the method #case is so general and could lead to conflicts, it is called #letter_case here.
@@ -94,13 +98,15 @@
a = 'ExampleString'
a.pascal_case? # => true
a.snake_case # => 'example_string'
a # => 'ExampleString'
+
# string variable manipulation
a.snake_case! # => 'example_string'
a # => 'example_string'
...
+
# identifiers
# got a other method name here because 'case' might be to common and cause conflicts
b = 'example'
b.letter_case # => :snake_case
b.letter_cases # => [ :snake_case, :camel_case, :dash_case, :word_case ]