lucky_case 0.1.0 → 0.2.1

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: 3a2cb0b71a39713fbfdcf1d1c829a682b2b5c3d3ab3e27848ed10ddb9b17f17c
4
- data.tar.gz: 47d28a8136f743a4bb8bd6b3687eecf40fd8bddc92554cd093616dc91a81b14a
3
+ metadata.gz: f78932c6caab460f362db13b18485d98b98b016dda12cc9750b9a649297c4587
4
+ data.tar.gz: 0240f607386929862771d4a44df92cd6f7dc186cdf11f2bd1a281463286b9c43
5
5
  SHA512:
6
- metadata.gz: 3c6f91d4e248c1c54fff4f25c168a34010dcadf12de9dedf488e50e4ca6f9235959990a6d59bd0f69b6cd6e7f5f72ffea2231b83745184e20ca2bcf0e529c22e
7
- data.tar.gz: c8dadeefe2192286ff3b9f3e756a6fc5fc8b0d640140ae38aaa1a300b526a12e2bc04c43b62b8112ee348b064e7a3348836da3516b188008e0e2ca910d402ac0
6
+ metadata.gz: 8455aad2bc3344d211556e326e073a68ee5ef02e2b9edab1f02454fab8841513323383f6d2e7679de21a641fce17f4438506fbc32ee72fdb2d249133d9f1a3b3
7
+ data.tar.gz: bc6cda1182cc9c1d83977d8a75fe726c543efc8713c3dab7761e58617d8ab92e7e4f00e31dc648d6df2518da6be7e8ec4b4cc5426a4554b15daf3a55046ff49b
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at yaml_extend.gemspec@mail.magynhard.de. All
58
+ reported by contacting the project team at lucky_case.gemspec@mail.magynhard.de. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/README.md CHANGED
@@ -30,13 +30,17 @@ You can either use the static LuckyCase class with its method or optionally monk
30
30
  require 'lucky_case'
31
31
 
32
32
  # converters
33
- LuckyCase.snake_case('ExamplePascalString') # => 'example_pascal_string'
34
- LuckyCase.upper_snake_case('Example-Train-String') # => 'EXAMPLE_TRAIN_STRING'
35
- LuckyCase.pascal_case('example_snake_string') # => 'ExampleSnakeString'
36
- LuckyCase.camel_case('example-dash-string') # => 'exampleDashString'
37
- LuckyCase.dash_case('ExamplePascalString') # => 'example-pascal-string'
38
- LuckyCase.upper_dash_case('ExamplePascalString') # => 'EXAMPLE-PASCAL-STRING'
39
- LuckyCase.train_case('example_snake_string') # => 'Example-Snake-String'
33
+ LuckyCase.snake_case('PascalToSnake') # => 'pascal_to_snake'
34
+ LuckyCase.upper_snake_case('Train-To-Upper-Snake') # => 'TRAIN_TO_UPPER_SNAKE'
35
+ LuckyCase.pascal_case('snake_to_pascal') # => 'SnakeToPascal'
36
+ LuckyCase.camel_case('dash-to-camel-case') # => 'dashToCamelCase'
37
+ LuckyCase.dash_case('PascalToDashCase') # => 'pascal-to-dash-case'
38
+ LuckyCase.upper_dash_case('PascalToUpperDash') # => 'PASCAL-TO-UPPER-DASH'
39
+ LuckyCase.train_case('snake_to_train_case') # => 'Snake-To-Train-Case'
40
+ LuckyCase.word_case('PascalToWordCase') # => 'pascal to word case'
41
+ LuckyCase.upper_word_case('PascalToUpperWord') # => 'PASCAL TO UPPER WORD'
42
+ LuckyCase.capital_word_case('snake_to_capital_word') # => 'Snake To Capital Word'
43
+ LuckyCase.sentence_case('snake_to_sentence_case') # => 'Snake to sentence case'
40
44
  LuckyCase.mixed_case('example_snake_string') # => 'Example-snake_STRING'
41
45
  # converter by type
42
46
  LuckyCase.convert_case('some_snake', :pascal_case) # => 'SomeSnake'
@@ -53,18 +57,22 @@ LuckyCase.deconstantize(SomeConstant) # => 'some_constant'
53
57
  LuckyCase.deconstantize(Some::PathExample::Folder, case_type: :camel_case) # => 'some/pathExample/folder'
54
58
  # identifier
55
59
  LuckyCase.case('this_can_only_be_snake_case') # => :snake_case
56
- LuckyCase.cases('multiple') # => [ :snake_case, :camel_case, :dash_case ]
60
+ LuckyCase.cases('validformultiple') # => [ :snake_case, :camel_case, :dash_case, :word_case ]
57
61
  # checkers
58
62
  LuckyCase.snake_case?('valid_snake_case') # => true
59
- LuckyCase.upper_snake_case?('inValidSnakeCase') # => false
63
+ LuckyCase.upper_snake_case?('UPPER_SNAKE') # => true
60
64
  LuckyCase.pascal_case?('PascalCase') # => true
61
65
  LuckyCase.camel_case?('camelCase') # => true
62
66
  LuckyCase.dash_case?('dash-case') # => true
63
67
  LuckyCase.upper_dash_case?('DASH-CASE') # => true
64
- LuckyCase.train?('Train-Case') # => true
68
+ LuckyCase.train_case?('Train-Case') # => true
69
+ LuckyCase.word_case?('word case') # => true
70
+ LuckyCase.upper_word_case?('UPPER WORD CASE') # => true
71
+ LuckyCase.capital_word_case?('Capital Word Case') # => true
72
+ LuckyCase.sentence_case?('Sentence case string') # => true
65
73
  LuckyCase.mixed_case?('mixed_Case') # => true
66
74
  LuckyCase.upper_case?('UPPER50984') # => true
67
- LuckyCase.lower_case?('mixed_Case') # => true
75
+ LuckyCase.lower_case?('lower_cheese') # => true
68
76
  LuckyCase.capital?('Some') # => true
69
77
  LuckyCase.capitalized?('some') # => false
70
78
  ```
@@ -106,7 +114,7 @@ And then execute:
106
114
 
107
115
  Or install it yourself by:
108
116
 
109
- $ gem install yaml_extend
117
+ $ gem install lucky_case
110
118
 
111
119
 
112
120
 
@@ -18,6 +18,10 @@ module LuckyCase
18
18
  dash_case: /^([[:lower:]]){1}[[:lower:]\-0-9]*[[:lower:]0-9]+$/,
19
19
  upper_dash_case: /^([[:upper:]]){1}[[:upper:]\-0-9]*[[:upper:]0-9]+$/,
20
20
  train_case: /^([[:upper:]][[:lower:]0-9]*\-|[0-9]+\-)*([[:upper:]][[:lower:]0-9]*)$/,
21
+ word_case: /^[[:lower:]]{1}[[:lower:] 0-9]+$/,
22
+ upper_word_case: /^[[:upper:]]{1}[[:upper:] 0-9]+$/,
23
+ capital_word_case: /^([[:upper:]][[:lower:]0-9]*\ |[0-9]+\ )*([[:upper:]][[:lower:]0-9]*)$/,
24
+ sentence_case: /^[[:upper:]]{1}[[:lower:] 0-9]+$/,
21
25
  mixed_case: /^[[:upper:][:lower:]][[:upper:][:lower:]_\-0-9]*$/,
22
26
  }
23
27
 
@@ -391,6 +395,146 @@ module LuckyCase
391
395
  _case_match? s, :train_case
392
396
  end
393
397
 
398
+ #----------------------------------------------------------------------------------------------------
399
+ # WORD CASE
400
+ #----------------------------------------------------------------------------------------------------
401
+
402
+ # Converts the given string from any case
403
+ # into word case
404
+ #
405
+ # @example conversion
406
+ # 'this-isAnExample_string' => 'this is an example string'
407
+ #
408
+ # @param [String] string to convert
409
+ # @param [Boolean] preserve_prefixed_underscores
410
+ # @return [String]
411
+ def self.word_case(string, preserve_prefixed_underscores: true)
412
+ a = split_case_string string
413
+ converted = a.join(' ')
414
+ if preserve_prefixed_underscores
415
+ underscores_at_start(string) + converted
416
+ else
417
+ converted
418
+ end
419
+ end
420
+
421
+ # Checks if the string is word case
422
+ #
423
+ # @param [String] string to check
424
+ # @param [Boolean] allow_prefixed_underscores
425
+ # @return [Boolean]
426
+ def self.word_case?(string, allow_prefixed_underscores: true)
427
+ s = if allow_prefixed_underscores
428
+ cut_underscores_at_start string
429
+ else
430
+ string
431
+ end
432
+ _case_match? s, :word_case
433
+ end
434
+
435
+ # Converts the given string from any case
436
+ # into upper word case
437
+ #
438
+ # @example conversion
439
+ # 'this-isAnExample_string' => 'THIS IS AN EXAMPLE STRING'
440
+ #
441
+ # @param [String] string to convert
442
+ # @param [Boolean] preserve_prefixed_underscores
443
+ # @return [String]
444
+ def self.upper_word_case(string, preserve_prefixed_underscores: true)
445
+ a = split_case_string string
446
+ converted = a.map { |e| upper_case e }.join(' ')
447
+ if preserve_prefixed_underscores
448
+ underscores_at_start(string) + converted
449
+ else
450
+ converted
451
+ end
452
+ end
453
+
454
+ # Checks if the string is upper word case
455
+ #
456
+ # @param [String] string to check
457
+ # @param [Boolean] allow_prefixed_underscores
458
+ # @return [Boolean]
459
+ def self.upper_word_case?(string, allow_prefixed_underscores: true)
460
+ s = if allow_prefixed_underscores
461
+ cut_underscores_at_start string
462
+ else
463
+ string
464
+ end
465
+ _case_match? s, :upper_word_case
466
+ end
467
+
468
+ # Converts the given string from any case
469
+ # into capital word case
470
+ #
471
+ # @example conversion
472
+ # 'this-isAnExample_string' => 'This Is An Example String'
473
+ #
474
+ # @param [String] string to convert
475
+ # @param [Boolean] preserve_prefixed_underscores
476
+ # @return [String]
477
+ def self.capital_word_case(string, preserve_prefixed_underscores: true)
478
+ a = split_case_string string
479
+ converted = a.map { |e| capital e }.join(' ')
480
+ if preserve_prefixed_underscores
481
+ underscores_at_start(string) + converted
482
+ else
483
+ converted
484
+ end
485
+ end
486
+
487
+ # Checks if the string is capital word case
488
+ #
489
+ # @param [String] string to check
490
+ # @param [Boolean] allow_prefixed_underscores
491
+ # @return [Boolean]
492
+ def self.capital_word_case?(string, allow_prefixed_underscores: true)
493
+ s = if allow_prefixed_underscores
494
+ cut_underscores_at_start string
495
+ else
496
+ string
497
+ end
498
+ _case_match? s, :capital_word_case
499
+ end
500
+
501
+ #----------------------------------------------------------------------------------------------------
502
+ # SENTENCE CASE
503
+ #----------------------------------------------------------------------------------------------------
504
+
505
+ # Converts the given string from any case
506
+ # into sentence case
507
+ #
508
+ # @example conversion
509
+ # 'this-isAnExample_string' => 'This is an example string'
510
+ #
511
+ # @param [String] string to convert
512
+ # @param [Boolean] preserve_prefixed_underscores
513
+ # @return [String]
514
+ def self.sentence_case(string, preserve_prefixed_underscores: true)
515
+ a = split_case_string string
516
+ converted = capital(a.join(' '))
517
+ if preserve_prefixed_underscores
518
+ underscores_at_start(string) + converted
519
+ else
520
+ converted
521
+ end
522
+ end
523
+
524
+ # Checks if the string is sentence case
525
+ #
526
+ # @param [String] string to check
527
+ # @param [Boolean] allow_prefixed_underscores
528
+ # @return [Boolean]
529
+ def self.sentence_case?(string, allow_prefixed_underscores: true)
530
+ s = if allow_prefixed_underscores
531
+ cut_underscores_at_start string
532
+ else
533
+ string
534
+ end
535
+ _case_match? s, :sentence_case
536
+ end
537
+
394
538
  #----------------------------------------------------------------------------------------------------
395
539
  # CAPITALIZE
396
540
  #----------------------------------------------------------------------------------------------------
@@ -539,7 +683,7 @@ module LuckyCase
539
683
  # @param [Boolean] preserve_prefixed_underscores
540
684
  # @return [Constant]
541
685
  def self.constantize(string)
542
- s = string.gsub('/','::')
686
+ s = string.gsub('/', '::')
543
687
  constants = if s.include? '::'
544
688
  s.split('::')
545
689
  else
@@ -627,6 +771,7 @@ module LuckyCase
627
771
  def self.split_case_string(string)
628
772
  s = cut_underscores_at_start string
629
773
  s = s.gsub(/([[:upper:]])/, '_\1') unless upper_case? s # prepend all upper characters with underscore
774
+ s = s.gsub(' ', '_') # replace all spaces with underscore
630
775
  s = s.gsub('-', '_') # replace all dashes with underscore
631
776
  s = cut_underscores_at_start s
632
777
  s.downcase.split('_').reject(&:empty?) # split everything by underscore
@@ -286,6 +286,110 @@ class String
286
286
  LuckyCase.train_case? self, allow_prefixed_underscores: allow_prefixed_underscores
287
287
  end
288
288
 
289
+ #----------------------------------------------------------------------------------------------------
290
+ # WORD CASE
291
+ #----------------------------------------------------------------------------------------------------
292
+
293
+ # Converts the given string from any case
294
+ # into word case
295
+ #
296
+ # @example conversion
297
+ # 'this-isAnExample_string' => 'this is an example string'
298
+ #
299
+ # @param [Boolean] preserve_prefixed_underscores
300
+ # @return [String]
301
+ def word_case(preserve_prefixed_underscores: true)
302
+ LuckyCase.word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
303
+ end
304
+
305
+ def word_case!(preserve_prefixed_underscores: true)
306
+ set_self_value self.word_case preserve_prefixed_underscores: preserve_prefixed_underscores
307
+ end
308
+
309
+ # Checks if the string is word case
310
+ #
311
+ # @param [Boolean] allow_prefixed_underscores
312
+ # @return [Boolean]
313
+ def word_case?(allow_prefixed_underscores: true)
314
+ LuckyCase.word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
315
+ end
316
+
317
+ # Converts the given string from any case
318
+ # into upper word case
319
+ #
320
+ # @example conversion
321
+ # 'this-isAnExample_string' => 'THIS IS AN EXAMPLE STRING'
322
+ #
323
+ # @param [Boolean] preserve_prefixed_underscores
324
+ # @return [String]
325
+ def upper_word_case(preserve_prefixed_underscores: true)
326
+ LuckyCase.upper_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
327
+ end
328
+
329
+ def upper_word_case!(preserve_prefixed_underscores: true)
330
+ set_self_value self.upper_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
331
+ end
332
+
333
+ # Checks if the string is upper word case
334
+ #
335
+ # @param [Boolean] allow_prefixed_underscores
336
+ # @return [Boolean]
337
+ def upper_word_case?(allow_prefixed_underscores: true)
338
+ LuckyCase.upper_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
339
+ end
340
+
341
+ # Converts the given string from any case
342
+ # into capital word case
343
+ #
344
+ # @example conversion
345
+ # 'this-isAnExample_string' => 'This Is An Example String'
346
+ #
347
+ # @param [Boolean] preserve_prefixed_underscores
348
+ # @return [String]
349
+ def capital_word_case(preserve_prefixed_underscores: true)
350
+ LuckyCase.capital_word_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
351
+ end
352
+
353
+ def capital_word_case!(preserve_prefixed_underscores: true)
354
+ set_self_value self.capital_word_case preserve_prefixed_underscores: preserve_prefixed_underscores
355
+ end
356
+
357
+ # Checks if the string is capital word case
358
+ #
359
+ # @param [Boolean] allow_prefixed_underscores
360
+ # @return [Boolean]
361
+ def capital_word_case?(allow_prefixed_underscores: true)
362
+ LuckyCase.capital_word_case? self, allow_prefixed_underscores: allow_prefixed_underscores
363
+ end
364
+
365
+ #----------------------------------------------------------------------------------------------------
366
+ # SENTENCE CASE
367
+ #----------------------------------------------------------------------------------------------------
368
+
369
+ # Converts the given string from any case
370
+ # into sentence case
371
+ #
372
+ # @example conversion
373
+ # 'this-isAnExample_string' => 'This is an example string'
374
+ #
375
+ # @param [Boolean] preserve_prefixed_underscores
376
+ # @return [String]
377
+ def sentence_case(preserve_prefixed_underscores: true)
378
+ LuckyCase.sentence_case self, preserve_prefixed_underscores: preserve_prefixed_underscores
379
+ end
380
+
381
+ def sentence_case!(preserve_prefixed_underscores: true)
382
+ set_self_value self.sentence_case preserve_prefixed_underscores: preserve_prefixed_underscores
383
+ end
384
+
385
+ # Checks if the string is sentence case
386
+ #
387
+ # @param [Boolean] allow_prefixed_underscores
388
+ # @return [Boolean]
389
+ def sentence_case?(allow_prefixed_underscores: true)
390
+ LuckyCase.sentence_case? self, allow_prefixed_underscores: allow_prefixed_underscores
391
+ end
392
+
289
393
  #----------------------------------------------------------------------------------------------------
290
394
  # CAPITALIZE
291
395
  #----------------------------------------------------------------------------------------------------
@@ -1,3 +1,3 @@
1
1
  module LuckyCase
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.1'.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.1.0
4
+ version: 0.2.1
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-08-11 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler