core_extended 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,21 +12,21 @@ class String
12
12
  alias_method :upcase_ignoring_accents!, :upcase!
13
13
  def upcase!
14
14
  ACCENTS_MAPPING.each { |map| tr! map[:downcase], map[:upcase] }
15
- upcase_ignoring_accents! || self
15
+ upcase_ignoring_accents!
16
16
  end
17
17
 
18
18
  def upcase
19
- self.dup.upcase!
19
+ self.dup.tap(&:upcase!)
20
20
  end
21
21
 
22
22
  alias_method :downcase_ignoring_accents!, :downcase!
23
23
  def downcase!
24
24
  ACCENTS_MAPPING.each { |map| tr! map[:upcase], map[:downcase] }
25
- downcase_ignoring_accents! || self
25
+ downcase_ignoring_accents!
26
26
  end
27
27
 
28
28
  def downcase
29
- self.dup.downcase!
29
+ self.dup.tap(&:downcase!)
30
30
  end
31
31
 
32
32
  def unaccented!
@@ -34,19 +34,22 @@ class String
34
34
  tr! map[:upcase], map[:letter]
35
35
  tr! map[:downcase], map[:letter].downcase
36
36
  end
37
- self
37
+ nil
38
38
  end
39
39
 
40
40
  def unaccented
41
- self.dup.unaccented!
41
+ self.dup.tap(&:unaccented!)
42
42
  end
43
43
 
44
44
  def normalized!
45
- self.unaccented!.downcase!
45
+ self.strip!
46
+ self.gsub! /\s/, '_'
47
+ self.unaccented!
48
+ self.downcase!
46
49
  end
47
50
 
48
51
  def normalized
49
- self.dup.normalized!
52
+ self.dup.tap(&:normalized!)
50
53
  end
51
54
 
52
55
  end
@@ -1,3 +1,3 @@
1
1
  module CoreExtended
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/string_spec.rb CHANGED
@@ -8,25 +8,27 @@ describe String do
8
8
  it 'Only accented' do
9
9
  'áÈïÔú'.upcase.must_equal 'ÁÈÏÔÚ'
10
10
  end
11
-
11
+
12
12
  it 'Without accents' do
13
13
  'aEiOu'.upcase.must_equal 'AEIOU'
14
14
  end
15
15
 
16
- it 'Mixed' do
17
- 'áEïÔu'.upcase.must_equal 'ÁEÏÔU'
16
+ it 'Keep itself' do
17
+ string = 'áèiÖU'
18
+ string.upcase.must_equal 'ÁÈIÖU'
19
+ string.must_equal 'áèiÖU'
18
20
  end
19
21
 
20
22
  it 'Change itself' do
21
23
  string = 'áèiÖU'
22
- string.upcase!.must_equal 'ÁÈIÖU'
24
+ string.upcase!
23
25
  string.must_equal 'ÁÈIÖU'
24
26
  end
25
27
 
26
28
  end
27
29
 
28
30
  describe 'Downcase' do
29
-
31
+
30
32
  it 'Only accented' do
31
33
  'áÈïÔú'.downcase.must_equal 'áèïôú'
32
34
  end
@@ -35,13 +37,15 @@ describe String do
35
37
  'aEiOu'.downcase.must_equal 'aeiou'
36
38
  end
37
39
 
38
- it 'Mixed' do
39
- 'áEïÔu'.downcase.must_equal 'áeïôu'
40
+ it 'Keep itself' do
41
+ string = 'áèiÖU'
42
+ string.downcase.must_equal 'áèiöu'
43
+ string.must_equal 'áèiÖU'
40
44
  end
41
45
 
42
46
  it 'Change itself' do
43
47
  string = 'ÁÈIöu'
44
- string.downcase!.must_equal 'áèiöu'
48
+ string.downcase!
45
49
  string.must_equal 'áèiöu'
46
50
  end
47
51
 
@@ -50,33 +54,53 @@ describe String do
50
54
  describe 'Unaccented' do
51
55
 
52
56
  it 'Transform keeping case' do
53
- string = 'Estas son mís létras MÁL acentúadäs y répetidâs íntëntândö ûtîlïzàr tôdas las varïantês'
54
- string.unaccented.must_equal 'Estas son mis letras MAL acentuadas y repetidas intentando utilizar todas las variantes'
55
- string.must_equal 'Estas son mís létras MÁL acentúadäs y répetidâs íntëntândö ûtîlïzàr tôdas las varïantês'
57
+ 'LétterS wÏth DifFèrent câse ÂND Äccents'.unaccented.must_equal 'LetterS wIth DifFerent case AND Accents'
58
+ end
59
+
60
+ it 'Keep itself' do
61
+ string = 'áëÌôÛ'
62
+ string.unaccented.must_equal 'aeIoU'
63
+ string.must_equal 'áëÌôÛ'
56
64
  end
57
65
 
58
66
  it 'Change itself' do
59
67
  string = 'áëÌôÛ'
60
- string.unaccented!.must_equal 'aeIoU'
68
+ string.unaccented!
61
69
  string.must_equal 'aeIoU'
62
70
  end
63
-
71
+
64
72
  end
65
73
 
66
74
  describe 'Normalized' do
67
-
68
- it 'Case and accents' do
69
- string = 'LétterS wÏth DifFèrent case ÂND Äccents'
70
- string.normalized.must_equal 'letters with different case and accents'
71
- string.must_equal 'LétterS wÏth DifFèrent case ÂND Äccents'
75
+
76
+ it 'Downcase' do
77
+ 'AeIoU'.normalized.must_equal 'aeiou'
78
+ end
79
+
80
+ it 'Remove accents' do
81
+ 'áèïôu'.normalized.must_equal 'aeiou'
82
+ end
83
+
84
+ it 'Replace spaces with underscore' do
85
+ 'this is a sample'.normalized.must_equal 'this_is_a_sample'
86
+ end
87
+
88
+ it 'Strip' do
89
+ ' text '.normalized.must_equal 'text'
90
+ end
91
+
92
+ it 'Keep itself' do
93
+ string = 'LétterS wÏth DifFèrent câse ÂND Äccents'
94
+ string.normalized.must_equal 'letters_with_different_case_and_accents'
95
+ string.must_equal 'LétterS wÏth DifFèrent câse ÂND Äccents'
72
96
  end
73
97
 
74
98
  it 'Change itself' do
75
- string = 'SámPlÊ'
76
- string.normalized!.must_equal 'sample'
77
- string.must_equal 'sample'
99
+ string = 'LétterS wÏth DifFèrent câse ÂND Äccents'
100
+ string.normalized!
101
+ string.must_equal 'letters_with_different_case_and_accents'
78
102
  end
79
103
 
80
104
  end
81
105
 
82
- end
106
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core_extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: