Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/lucky_case/string.rb
Overview
LuckyCase version to add methods directly to string by monkey patching
can be included this way by
require 'lucky_case/string'
Instance Method Summary collapse
-
#camel_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into camel case.
- #camel_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#camel_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is camel case.
-
#capital(skip_prefixed_underscores: false) ⇒ String
Convert the first character to capital.
- #capital!(skip_prefixed_underscores: false) ⇒ Object
-
#capital?(skip_prefixed_underscores: false) ⇒ Boolean
Check if the strings first character is a capital letter.
-
#capital_word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into capital word case.
- #capital_word_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#capital_word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is capital word case.
-
#capitalize(skip_prefixed_underscores: false) ⇒ String
Convert the first character to capital.
- #capitalize!(skip_prefixed_underscores: false) ⇒ Object
-
#capitalized?(skip_prefixed_underscores: false) ⇒ Boolean
Check if the strings first character is a capital letter.
-
#constantize ⇒ Constant
Convert the string from any case into pascal case and casts it into a constant.
-
#convert_case(case_type, preserve_prefixed_underscores: true) ⇒ String
Convert a string into the given case type.
- #convert_case!(case_type, preserve_prefixed_underscores: true) ⇒ Object
-
#dash_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into dash case.
- #dash_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#dash_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is dash case.
-
#lower_case ⇒ String
Convert all characters inside the string into lower case.
- #lower_case! ⇒ Object
-
#lower_case? ⇒ Boolean
Check if all characters inside the string are lower case.
-
#lucky_case(allow_prefixed_underscores: true) ⇒ Symbol?
Get type of case of string (one key of LuckyCase.CASES).
-
#lucky_cases(allow_prefixed_underscores: true) ⇒ Array<Symbol>?
Get types of cases of string (keys of LuckyCase.CASES).
-
#mixed_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into mixed case.
- #mixed_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#mixed_case? ⇒ Boolean
Check if the string is a valid mixed case (without special characters!).
-
#pascal_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into pascal case.
- #pascal_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#pascal_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper pascal case.
-
#sentence_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into sentence case.
- #sentence_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#sentence_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is sentence case.
-
#snake_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into snake case.
- #snake_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#snake_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is snake case.
-
#swap_case(preserve_prefixed_underscores: false) ⇒ String
Swaps character cases in string.
-
#swap_case!(preserve_prefixed_underscores: false) ⇒ Object
—————————————————————————————————-.
-
#train_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into train case.
- #train_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#train_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is train case.
-
#upper_case ⇒ String
Convert all characters inside the string into upper case.
- #upper_case! ⇒ Object
-
#upper_case? ⇒ Boolean
Check if all characters inside the string are upper case.
-
#upper_dash_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper dash case.
- #upper_dash_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#upper_dash_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper dash case.
-
#upper_snake_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper snake case.
- #upper_snake_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#upper_snake_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper snake case.
-
#upper_word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper word case.
- #upper_word_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#upper_word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper word case.
-
#valid_case_string? ⇒ Boolean
Check if the string matches any of the available cases.
-
#word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into word case.
- #word_case!(preserve_prefixed_underscores: true) ⇒ Object
-
#word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is word case.
Instance Method Details
#camel_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into camel case
200 201 202 |
# File 'lib/lucky_case/string.rb', line 200 def camel_case(preserve_prefixed_underscores: true) LuckyCase.camel_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#camel_case!(preserve_prefixed_underscores: true) ⇒ Object
204 205 206 |
# File 'lib/lucky_case/string.rb', line 204 def camel_case!(preserve_prefixed_underscores: true) set_self_value self.camel_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#camel_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is camel case
212 213 214 |
# File 'lib/lucky_case/string.rb', line 212 def camel_case?(allow_prefixed_underscores: true) LuckyCase.camel_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#capital(skip_prefixed_underscores: false) ⇒ String
Convert the first character to capital
408 409 410 |
# File 'lib/lucky_case/string.rb', line 408 def capital(skip_prefixed_underscores: false) LuckyCase.capitalize self, skip_prefixed_underscores: skip_prefixed_underscores end |
#capital!(skip_prefixed_underscores: false) ⇒ Object
420 421 422 |
# File 'lib/lucky_case/string.rb', line 420 def capital!(skip_prefixed_underscores: false) set_self_value self.capitalize skip_prefixed_underscores: skip_prefixed_underscores end |
#capital?(skip_prefixed_underscores: false) ⇒ Boolean
Check if the strings first character is a capital letter
432 433 434 |
# File 'lib/lucky_case/string.rb', line 432 def capital?(skip_prefixed_underscores: false) LuckyCase.capital? self, skip_prefixed_underscores: skip_prefixed_underscores end |
#capital_word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into capital word case
356 357 358 |
# File 'lib/lucky_case/string.rb', line 356 def capital_word_case(preserve_prefixed_underscores: true) LuckyCase.capital_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#capital_word_case!(preserve_prefixed_underscores: true) ⇒ Object
360 361 362 |
# File 'lib/lucky_case/string.rb', line 360 def capital_word_case!(preserve_prefixed_underscores: true) set_self_value self.capital_word_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#capital_word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is capital word case
368 369 370 |
# File 'lib/lucky_case/string.rb', line 368 def capital_word_case?(allow_prefixed_underscores: true) LuckyCase.capital_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#capitalize(skip_prefixed_underscores: false) ⇒ String
Convert the first character to capital
416 417 418 |
# File 'lib/lucky_case/string.rb', line 416 def capitalize(skip_prefixed_underscores: false) self.capital skip_prefixed_underscores: skip_prefixed_underscores end |
#capitalize!(skip_prefixed_underscores: false) ⇒ Object
424 425 426 |
# File 'lib/lucky_case/string.rb', line 424 def capitalize!(skip_prefixed_underscores: false) self.capital! skip_prefixed_underscores: skip_prefixed_underscores end |
#capitalized?(skip_prefixed_underscores: false) ⇒ Boolean
Check if the strings first character is a capital letter
440 441 442 |
# File 'lib/lucky_case/string.rb', line 440 def capitalized?(skip_prefixed_underscores: false) self.capital? skip_prefixed_underscores: skip_prefixed_underscores end |
#constantize ⇒ Constant
Convert the string from any case into pascal case and casts it into a constant
510 511 512 |
# File 'lib/lucky_case/string.rb', line 510 def constantize() LuckyCase.constantize self end |
#convert_case(case_type, preserve_prefixed_underscores: true) ⇒ String
Convert a string into the given case type
41 42 43 |
# File 'lib/lucky_case/string.rb', line 41 def convert_case(case_type, preserve_prefixed_underscores: true) LuckyCase.convert_case self, case_type, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#convert_case!(case_type, preserve_prefixed_underscores: true) ⇒ Object
45 46 47 |
# File 'lib/lucky_case/string.rb', line 45 def convert_case!(case_type, preserve_prefixed_underscores: true) set_self_value self.convert_case(case_type, preserve_prefixed_underscores: preserve_prefixed_underscores) end |
#dash_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into dash case
228 229 230 |
# File 'lib/lucky_case/string.rb', line 228 def dash_case(preserve_prefixed_underscores: true) LuckyCase.dash_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#dash_case!(preserve_prefixed_underscores: true) ⇒ Object
232 233 234 |
# File 'lib/lucky_case/string.rb', line 232 def dash_case!(preserve_prefixed_underscores: true) set_self_value self.dash_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#dash_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is dash case
240 241 242 |
# File 'lib/lucky_case/string.rb', line 240 def dash_case?(allow_prefixed_underscores: true) LuckyCase.dash_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#lower_case ⇒ String
Convert all characters inside the string into lower case
93 94 95 |
# File 'lib/lucky_case/string.rb', line 93 def lower_case() LuckyCase.lower_case self end |
#lower_case! ⇒ Object
97 98 99 |
# File 'lib/lucky_case/string.rb', line 97 def lower_case!() set_self_value self.lower_case end |
#lower_case? ⇒ Boolean
Check if all characters inside the string are lower case
104 105 106 |
# File 'lib/lucky_case/string.rb', line 104 def lower_case?() LuckyCase.lower_case? self end |
#lucky_case(allow_prefixed_underscores: true) ⇒ Symbol?
Get type of case of string (one key of LuckyCase.CASES)
If more than one case matches, the first match wins. Match prio is the order of the regex in LuckyCase.CASES
If you want or need to know all cases, use plural version of this method
If you want to check explicitly for one case, use its check method, e.g. snake_case? for snake_case, etc…
24 25 26 |
# File 'lib/lucky_case/string.rb', line 24 def lucky_case(allow_prefixed_underscores: true) LuckyCase.case self, allow_prefixed_underscores: allow_prefixed_underscores end |
#lucky_cases(allow_prefixed_underscores: true) ⇒ Array<Symbol>?
Get types of cases of string (keys of LuckyCase.CASES)
32 33 34 |
# File 'lib/lucky_case/string.rb', line 32 def lucky_cases(allow_prefixed_underscores: true) LuckyCase.cases self, allow_prefixed_underscores: allow_prefixed_underscores end |
#mixed_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into mixed case
456 457 458 |
# File 'lib/lucky_case/string.rb', line 456 def mixed_case(preserve_prefixed_underscores: true) LuckyCase.mixed_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#mixed_case!(preserve_prefixed_underscores: true) ⇒ Object
460 461 462 |
# File 'lib/lucky_case/string.rb', line 460 def mixed_case!(preserve_prefixed_underscores: true) set_self_value self.mixed_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#mixed_case? ⇒ Boolean
Check if the string is a valid mixed case (without special characters!)
467 468 469 |
# File 'lib/lucky_case/string.rb', line 467 def mixed_case?() LuckyCase.mixed_case? self end |
#pascal_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into pascal case
172 173 174 |
# File 'lib/lucky_case/string.rb', line 172 def pascal_case(preserve_prefixed_underscores: true) LuckyCase.pascal_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#pascal_case!(preserve_prefixed_underscores: true) ⇒ Object
176 177 178 |
# File 'lib/lucky_case/string.rb', line 176 def pascal_case!(preserve_prefixed_underscores: true) set_self_value self.pascal_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#pascal_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper pascal case
184 185 186 |
# File 'lib/lucky_case/string.rb', line 184 def pascal_case?(allow_prefixed_underscores: true) LuckyCase.pascal_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#sentence_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into sentence case
384 385 386 |
# File 'lib/lucky_case/string.rb', line 384 def sentence_case(preserve_prefixed_underscores: true) LuckyCase.sentence_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#sentence_case!(preserve_prefixed_underscores: true) ⇒ Object
388 389 390 |
# File 'lib/lucky_case/string.rb', line 388 def sentence_case!(preserve_prefixed_underscores: true) set_self_value self.sentence_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#sentence_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is sentence case
396 397 398 |
# File 'lib/lucky_case/string.rb', line 396 def sentence_case?(allow_prefixed_underscores: true) LuckyCase.sentence_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#snake_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into snake case
120 121 122 |
# File 'lib/lucky_case/string.rb', line 120 def snake_case(preserve_prefixed_underscores: true) LuckyCase.snake_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#snake_case!(preserve_prefixed_underscores: true) ⇒ Object
124 125 126 |
# File 'lib/lucky_case/string.rb', line 124 def snake_case!(preserve_prefixed_underscores: true) set_self_value self.snake_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#snake_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is snake case
132 133 134 |
# File 'lib/lucky_case/string.rb', line 132 def snake_case?(allow_prefixed_underscores: true) LuckyCase.snake_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#swap_case(preserve_prefixed_underscores: false) ⇒ String
Swaps character cases in string
lower case to upper case upper case to lower case dash to underscore underscore to dash
487 488 489 |
# File 'lib/lucky_case/string.rb', line 487 def swap_case(preserve_prefixed_underscores: false) LuckyCase.swap_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#swap_case!(preserve_prefixed_underscores: false) ⇒ Object
493 494 495 |
# File 'lib/lucky_case/string.rb', line 493 def swap_case!(preserve_prefixed_underscores: false) set_self_value self.swap_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#train_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into train case
280 281 282 |
# File 'lib/lucky_case/string.rb', line 280 def train_case(preserve_prefixed_underscores: true) LuckyCase.train_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#train_case!(preserve_prefixed_underscores: true) ⇒ Object
284 285 286 |
# File 'lib/lucky_case/string.rb', line 284 def train_case!(preserve_prefixed_underscores: true) set_self_value self.train_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#train_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is train case
292 293 294 |
# File 'lib/lucky_case/string.rb', line 292 def train_case?(allow_prefixed_underscores: true) LuckyCase.train_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#upper_case ⇒ String
Convert all characters inside the string into upper case
67 68 69 |
# File 'lib/lucky_case/string.rb', line 67 def upper_case() LuckyCase.upper_case self end |
#upper_case! ⇒ Object
71 72 73 |
# File 'lib/lucky_case/string.rb', line 71 def upper_case!() set_self_value self.upper_case end |
#upper_case? ⇒ Boolean
Check if all characters inside the string are upper case
78 79 80 |
# File 'lib/lucky_case/string.rb', line 78 def upper_case?() LuckyCase.upper_case? self end |
#upper_dash_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper dash case
252 253 254 |
# File 'lib/lucky_case/string.rb', line 252 def upper_dash_case(preserve_prefixed_underscores: true) LuckyCase.upper_dash_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_dash_case!(preserve_prefixed_underscores: true) ⇒ Object
256 257 258 |
# File 'lib/lucky_case/string.rb', line 256 def upper_dash_case!(preserve_prefixed_underscores: true) set_self_value self.upper_dash_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_dash_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper dash case
264 265 266 |
# File 'lib/lucky_case/string.rb', line 264 def upper_dash_case?(allow_prefixed_underscores: true) LuckyCase.upper_dash_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#upper_snake_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper snake case
144 145 146 |
# File 'lib/lucky_case/string.rb', line 144 def upper_snake_case(preserve_prefixed_underscores: true) LuckyCase.upper_snake_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_snake_case!(preserve_prefixed_underscores: true) ⇒ Object
148 149 150 |
# File 'lib/lucky_case/string.rb', line 148 def upper_snake_case!(preserve_prefixed_underscores: true) set_self_value self.upper_snake_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_snake_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper snake case
156 157 158 |
# File 'lib/lucky_case/string.rb', line 156 def upper_snake_case?(allow_prefixed_underscores: true) LuckyCase.upper_snake_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#upper_word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into upper word case
332 333 334 |
# File 'lib/lucky_case/string.rb', line 332 def upper_word_case(preserve_prefixed_underscores: true) LuckyCase.upper_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_word_case!(preserve_prefixed_underscores: true) ⇒ Object
336 337 338 |
# File 'lib/lucky_case/string.rb', line 336 def upper_word_case!(preserve_prefixed_underscores: true) set_self_value self.upper_word_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#upper_word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is upper word case
344 345 346 |
# File 'lib/lucky_case/string.rb', line 344 def upper_word_case?(allow_prefixed_underscores: true) LuckyCase.upper_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |
#valid_case_string? ⇒ Boolean
Check if the string matches any of the available cases
52 53 54 |
# File 'lib/lucky_case/string.rb', line 52 def valid_case_string?() LuckyCase.case(self) != nil end |
#word_case(preserve_prefixed_underscores: true) ⇒ String
Convert the given string from any case into word case
308 309 310 |
# File 'lib/lucky_case/string.rb', line 308 def word_case(preserve_prefixed_underscores: true) LuckyCase.word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores end |
#word_case!(preserve_prefixed_underscores: true) ⇒ Object
312 313 314 |
# File 'lib/lucky_case/string.rb', line 312 def word_case!(preserve_prefixed_underscores: true) set_self_value self.word_case preserve_prefixed_underscores: preserve_prefixed_underscores end |
#word_case?(allow_prefixed_underscores: true) ⇒ Boolean
Check if the string is word case
320 321 322 |
# File 'lib/lucky_case/string.rb', line 320 def word_case?(allow_prefixed_underscores: true) LuckyCase.word_case? self, allow_prefixed_underscores: allow_prefixed_underscores end |