accent-buster 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92de494461848c93cbc4edb566f1628665631af7
4
- data.tar.gz: 4fa2724528fb23df070692969f5a2337d46cce59
3
+ metadata.gz: f86425aa3da73ca42e26dd68f83b71c720037837
4
+ data.tar.gz: 36ce160d06487faee02247ade4690a6ac4293531
5
5
  SHA512:
6
- metadata.gz: 8e93e149c1d9009f153997b06ef6fc8d6fed01594040445bdbd65af66231a2c27eb587625b40c3ce72ce79c805fe91e596dd1becebff4b3f5370fec6c3bbcc6e
7
- data.tar.gz: f1692695e4d56162e4f88fae5df06d6f8460a434289e7c28517896467f58617ea4ebcd653f5fa308a6b675146e05f6af8a446bba3b58fb85a3961e9545c60061
6
+ metadata.gz: c0c459fdf1c4a21b7af99c056a99c6ceedba7b4ee91a313f5a2b6adf5b540b420ad731c81a977805375511f3f79893af8a5491bfab3a53fc3e0ef79ff2694c78
7
+ data.tar.gz: d69ce4b7ee938340905b4c5c87f9049cb16bce4e5123941fb9987b5b0d834140fea9294d147db3db756a5f836dc549e62104d744f71d4b55203917b26f7a1470
data/README.md CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  Add "String#accent\_buster" that replaces diacritics marks by their non-diacritic equivalents.
4
4
 
5
+ Modify "String#downcase", "String#downcase!", "String#upcase", "String#upcase!" to correctly handle diacritics.
6
+
5
7
  I made it because I don't want to add "ActiveSupport" to the projects everytime I need that (also, I'm too lazy to type the same thing all the time).
6
8
 
7
- This lib will have NO MORE than the very strictly necessary to replace diacritics, currently, it has 2 methods: "String#accent_buster" and "String#accent_buster!" (note the bang).
9
+ BTW, if you want to get really serious on that, the gem "UnicodeUtils" is a far better (and more complete) option. ^\_^
8
10
 
9
11
  Accent Buster uses refinements, so, ruby 2.0+ only.
10
12
 
@@ -32,6 +34,11 @@ using AccentBuster::StringExtension
32
34
  x = 'é você?'
33
35
  x.accent_buster!
34
36
  # => x = 'e voce'
37
+
38
+ 'ação'.upcase # => 'AÇÃO'
39
+ x = 'é você?'
40
+ x.upcase!
41
+ # => x = 'É VOCÊ?'
35
42
  ```
36
43
 
37
44
  ## Contributing
@@ -1,12 +1,17 @@
1
1
  module AccentBuster::StringExtension
2
2
  refine String do
3
+ ACCENT_DOWNCASE = 'áéíóúâêîôûäëïöüãõñç'
4
+ NO_ACCENT_DOWNCASE = 'aeiouaeiouaeiouaonc'
5
+ ACCENT_UPCASE = 'ÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ'
6
+ NO_ACCENT_UPCASE = 'AEIOUAEIOUAEIOUAONC'
7
+
3
8
  # Convert diacritics chars to their non-diacritic equivalents.
4
9
  #
5
10
  # Works for latin languages only.
6
11
  #
7
12
  # Returns a copy of the string with diacritics removed.
8
13
  def accent_buster
9
- self.tr('áéíóúâêîôûäëïöüãõñçÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ', 'aeiouaeiouaeiouaoncAEIOUAEIOUAEIOUAONC')
14
+ self.tr(ACCENT_DOWNCASE + ACCENT_UPCASE, NO_ACCENT_DOWNCASE + NO_ACCENT_UPCASE)
10
15
  end
11
16
 
12
17
  # Convert diacritics chars to their non-diacritic equivalents.
@@ -17,7 +22,25 @@ module AccentBuster::StringExtension
17
22
  #
18
23
  # Returns the string or nil if no changes were made.
19
24
  def accent_buster!
20
- self.tr!('áéíóúâêîôûäëïöüãõñçÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ', 'aeiouaeiouaeiouaoncAEIOUAEIOUAEIOUAONC')
25
+ self.tr!(ACCENT_DOWNCASE + ACCENT_UPCASE, NO_ACCENT_DOWNCASE + NO_ACCENT_UPCASE)
26
+ end
27
+
28
+ def downcase
29
+ super.tr(ACCENT_UPCASE, ACCENT_DOWNCASE)
30
+ end
31
+
32
+ def downcase!
33
+ super
34
+ self.tr!(ACCENT_UPCASE, ACCENT_DOWNCASE)
35
+ end
36
+
37
+ def upcase
38
+ super.tr(ACCENT_DOWNCASE, ACCENT_UPCASE)
39
+ end
40
+
41
+ def upcase!
42
+ super
43
+ self.tr!(ACCENT_DOWNCASE, ACCENT_UPCASE)
21
44
  end
22
45
  end
23
46
  end
@@ -1,3 +1,3 @@
1
1
  module AccentBuster
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accent-buster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronie Uliana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Add "String#accent_buster" that replaces diacritics marks by their non-diacritic
@@ -46,7 +46,7 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".gitignore"
49
+ - .gitignore
50
50
  - Gemfile
51
51
  - LICENSE
52
52
  - README.md
@@ -65,17 +65,17 @@ require_paths:
65
65
  - lib
66
66
  required_ruby_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '2.0'
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.2.0
78
+ rubygems_version: 2.1.11
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: 'Add "String#accent_buster" that replaces diacritics marks by their non-diacritic