remove_accents 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -2
- data/lib/remove_accents/configuration.rb +4 -2
- data/lib/remove_accents/version.rb +1 -1
- metadata +2 -3
- data/lib/extend_string.rb +0 -86
data/README.md
CHANGED
@@ -14,7 +14,7 @@ What you want in this case is "francois_leveille" or "francoisleveille" and this
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem '
|
17
|
+
gem 'remove_accents'
|
18
18
|
```
|
19
19
|
|
20
20
|
And then execute:
|
@@ -23,13 +23,15 @@ And then execute:
|
|
23
23
|
|
24
24
|
Or install it yourself as:
|
25
25
|
|
26
|
-
$ gem install
|
26
|
+
$ gem install remove_accents
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
30
|
|
31
31
|
===========
|
32
32
|
|
33
|
+
require 'remove_accents'
|
34
|
+
|
33
35
|
# Set a sample string to test things out
|
34
36
|
```ruby
|
35
37
|
mystring = "Ceci Est UN test : éàòù"
|
@@ -18,10 +18,12 @@ module RemoveAccents
|
|
18
18
|
'n' => [241],
|
19
19
|
'Y' => [221],
|
20
20
|
'y' => [253,255],
|
21
|
-
'
|
21
|
+
'Ae' => [306],
|
22
22
|
'ae' => [346],
|
23
|
-
'
|
23
|
+
'Oe' => [188],
|
24
24
|
'oe' => [189],
|
25
|
+
'Ue' => [220],
|
26
|
+
'ue' => [252],
|
25
27
|
'ss' => [223]
|
26
28
|
}
|
27
29
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remove_accents
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- LICENSE.txt
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
|
-
- lib/extend_string.rb
|
111
110
|
- lib/remove_accents.rb
|
112
111
|
- lib/remove_accents/base.rb
|
113
112
|
- lib/remove_accents/configuration.rb
|
data/lib/extend_string.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# RemoveAccents version 1.0.3 (c) 2008-2009 Solutions Informatiques Techniconseils inc.
|
2
|
-
#
|
3
|
-
# This module adds 2 methods to the string class.
|
4
|
-
# Up-to-date version and documentation available at:
|
5
|
-
#
|
6
|
-
# http://www.techniconseils.ca/en/scripts-remove-accents-ruby.php
|
7
|
-
#
|
8
|
-
# This script is available under the following license :
|
9
|
-
# Creative Commons Attribution-Share Alike 2.5.
|
10
|
-
#
|
11
|
-
# See full license and details at :
|
12
|
-
# http://creativecommons.org/licenses/by-sa/2.5/ca/
|
13
|
-
#
|
14
|
-
# Version history:
|
15
|
-
# * 1.0.3 : July 23 2009
|
16
|
-
# Corrected some incorrect character codes. Source is now wikipedia at:
|
17
|
-
# http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Related_character_maps
|
18
|
-
# Thanks to Raimon Fernandez for pointing out the incorrect codes.
|
19
|
-
# * 1.0.2 : October 29 2008
|
20
|
-
# Slightly optimized version of urlize - Jonathan Grenier (jgrenier@techniconseils.ca)
|
21
|
-
# * 1.0.1 : October 29 2008
|
22
|
-
# First public revision - Jonathan Grenier (jgrenier@techniconseils.ca)
|
23
|
-
#
|
24
|
-
|
25
|
-
class String
|
26
|
-
# The extended characters map used by removeaccents. The accented characters
|
27
|
-
# are coded here using their numerical equivalent to sidestep encoding issues.
|
28
|
-
# These correspond to ISO-8859-1 encoding.
|
29
|
-
# ACCENTS_MAPPING = {
|
30
|
-
# 'E' => [200,201,202,203],
|
31
|
-
# 'e' => [232,233,234,235],
|
32
|
-
# 'A' => [192,193,194,195,196,197],
|
33
|
-
# 'a' => [224,225,226,227,228,229,230],
|
34
|
-
# 'C' => [199],
|
35
|
-
# 'c' => [231],
|
36
|
-
# 'O' => [210,211,212,213,214,216],
|
37
|
-
# 'o' => [242,243,244,245,246,248],
|
38
|
-
# 'I' => [204,205,206,207],
|
39
|
-
# 'i' => [236,237,238,239],
|
40
|
-
# 'U' => [217,218,219,220],
|
41
|
-
# 'u' => [249,250,251,252],
|
42
|
-
# 'N' => [209],
|
43
|
-
# 'n' => [241],
|
44
|
-
# 'Y' => [221],
|
45
|
-
# 'y' => [253,255],
|
46
|
-
# 'AE' => [306],
|
47
|
-
# 'ae' => [346],
|
48
|
-
# 'OE' => [188],
|
49
|
-
# 'oe' => [189],
|
50
|
-
# 'ss' => [223]
|
51
|
-
# }
|
52
|
-
|
53
|
-
|
54
|
-
# Remove the accents from the string. Uses String::ACCENTS_MAPPING as the source map.
|
55
|
-
def removeaccents
|
56
|
-
str = String.new(self)
|
57
|
-
String::ACCENTS_MAPPING.each {|letter,accents|
|
58
|
-
packed = accents.pack('U*')
|
59
|
-
rxp = Regexp.new("[#{packed}]", nil, 'U')
|
60
|
-
str.gsub!(rxp, letter)
|
61
|
-
}
|
62
|
-
|
63
|
-
str
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
# Convert a string to a format suitable for a URL without ever using escaped characters.
|
68
|
-
# It calls strip, removeaccents, downcase (optional) then removes the spaces (optional)
|
69
|
-
# and finally removes any characters matching the default regexp (/[^-_A-Za-z0-9]/).
|
70
|
-
#
|
71
|
-
# Options
|
72
|
-
#
|
73
|
-
# * :downcase => call downcase on the string (defaults to true)
|
74
|
-
# * :convert_spaces => Convert space to underscore (defaults to false)
|
75
|
-
# * :regexp => The regexp matching characters that will be converting to an empty string (defaults to /[^-_A-Za-z0-9]/)
|
76
|
-
def urlize(options = {})
|
77
|
-
options[:downcase] ||= true
|
78
|
-
options[:convert_spaces] ||= false
|
79
|
-
options[:regexp] ||= /[^-_A-Za-z0-9]/
|
80
|
-
|
81
|
-
str = self.strip.removeaccents
|
82
|
-
str.downcase! if options[:downcase]
|
83
|
-
str.gsub!(/\ /,'_') if options[:convert_spaces]
|
84
|
-
str.gsub(options[:regexp], '')
|
85
|
-
end
|
86
|
-
end
|