accent_to_ascii 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/accent_to_ascii.rb +18 -11
- data/lib/accent_to_ascii/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e1b3456efd1dbc527f07aa580e425665fac2a8f
|
4
|
+
data.tar.gz: 85a928759cfc7db9fe38a9924d81768c5761c26d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f14c1846d46302bc2e56de59323dd757deb988c9766ab574ee3da61f0179426c5430a4ffc9879f3d7eca85909f3317e4bece264b108b8bd8c997f92d1954dc5
|
7
|
+
data.tar.gz: 80d203f099f8edf8526356c966237dad9757c546fd31f40f6ba5453b2ad9736e74e36e311a9e12f04685f01274a860dc77a11b1335d052f297c813fda773d26d
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
42
42
|
|
43
43
|
## Contributing
|
44
44
|
|
45
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/unieagle/accent_to_ascii. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
46
|
|
47
47
|
|
48
48
|
## License
|
data/lib/accent_to_ascii.rb
CHANGED
@@ -24,24 +24,31 @@ module AccentToAscii
|
|
24
24
|
'OE' => [188],
|
25
25
|
'oe' => [189]
|
26
26
|
}
|
27
|
+
|
28
|
+
class AccentToAscii
|
29
|
+
def self.accent_to_ascii(string)
|
30
|
+
string.tap do |s|
|
31
|
+
ACCENTS_MAPPING.each { |letter, accents| replace(s, letter, accents) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.replace(string, letter, accents)
|
38
|
+
packed = accents.pack('U*')
|
39
|
+
regex = Regexp.new("[#{packed}]", nil)
|
40
|
+
string.gsub!(regex, letter)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
27
44
|
end
|
28
45
|
|
29
46
|
class String
|
30
47
|
def accent_to_ascii(string = String.new(self))
|
31
|
-
string
|
32
|
-
AccentToAscii::ACCENTS_MAPPING.each { |letter, accents| replace(s, letter, accents) }
|
33
|
-
end
|
48
|
+
AccentToAscii::AccentToAscii.accent_to_ascii(string)
|
34
49
|
end
|
35
50
|
|
36
51
|
def accent_to_ascii!
|
37
52
|
accent_to_ascii(self)
|
38
53
|
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def replace(string, letter, accents)
|
43
|
-
packed = accents.pack('U*')
|
44
|
-
regex = Regexp.new("[#{packed}]", nil)
|
45
|
-
string.gsub!(regex, letter)
|
46
|
-
end
|
47
54
|
end
|