unlaut 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/unlaut.rb +49 -0
- data/test/unlaut_test.rb +9 -0
- data/unlaut.gemspec +18 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Axel Tetzlaff
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Unlaut
|
2
|
+
|
3
|
+
Adds a 'no_i18n' method to String, providing you with an accent and umlaut free version of it.
|
4
|
+
|
5
|
+
# Example:
|
6
|
+
irb(main):011:0> 'Hellö, Mr. Présidente'.no_i18n
|
7
|
+
=> "Hello, Mr. Presidente"
|
8
|
+
|
9
|
+
# Replacements can be configured
|
10
|
+
irb(main):012:0> Unlaut::Map.replace 'aeiuo', 'x'
|
11
|
+
irb(main):013:0> 'I hate vowels'.no_i18n
|
12
|
+
=> "I hxtx vxwxls"
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'unlaut'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install unlaut
|
27
|
+
|
28
|
+
## Rails
|
29
|
+
|
30
|
+
You have to require the lib at startup to actually get the *no_i18n* method. You can add an initializer to
|
31
|
+
|
32
|
+
config/initializers/unlaut.rb
|
33
|
+
|
34
|
+
where you then als can add own replacements:
|
35
|
+
|
36
|
+
require 'unlaut'
|
37
|
+
# loads the unlaut gem which adds a no_i18n method to strings to replace umlauts
|
38
|
+
|
39
|
+
# Unlaut::Map.replace 'x', 'y'
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/unlaut.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Unlaut
|
3
|
+
class Map
|
4
|
+
class << self
|
5
|
+
def replace(from, to)
|
6
|
+
if from.length > 1
|
7
|
+
from.each_char{|c| replace c, to}
|
8
|
+
else
|
9
|
+
@map ||= {}
|
10
|
+
@map[from] = to
|
11
|
+
@src_chars = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def src_chars
|
16
|
+
@src_chars ||= Regexp.new('[' + @map.keys.join() + ']')
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(string)
|
20
|
+
string.gsub(src_chars) {|char| @map[char] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
replace 'ÂÃÄÀÁÅÆ', 'A'
|
25
|
+
replace 'Ç', 'C'
|
26
|
+
replace 'ÈÉÊË', 'E'
|
27
|
+
replace 'ÌÍÎÏ', 'I'
|
28
|
+
replace 'Ð', 'D'
|
29
|
+
replace 'Ñ', 'N'
|
30
|
+
replace 'ÒÓÔÕÖØ', 'O'
|
31
|
+
replace 'ÙÚÛÜ', 'U'
|
32
|
+
replace 'ÞÝ', 'Y'
|
33
|
+
replace 'ÙÚÛÜÝ', 'U'
|
34
|
+
replace 'ß', 'ss'
|
35
|
+
replace 'àáâãäåæ', 'a'
|
36
|
+
replace 'ç', 'c'
|
37
|
+
replace 'èéêë', 'e'
|
38
|
+
replace 'ìíî', 'i'
|
39
|
+
replace 'ðñòóôõöø', 'o'
|
40
|
+
replace 'ùúûü', 'u'
|
41
|
+
replace 'ýþÿ', 'y'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class String
|
46
|
+
def no_i18n
|
47
|
+
Unlaut::Map.execute(self)
|
48
|
+
end
|
49
|
+
end
|
data/test/unlaut_test.rb
ADDED
data/unlaut.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "unlaut"
|
7
|
+
gem.version = '0.3'
|
8
|
+
gem.authors = ["Axel Tetzlaff"]
|
9
|
+
gem.email = ["axel.tetzlaff@fortytools.com"]
|
10
|
+
gem.description = %q{Replace umlauts and other unwanted chars in strings}
|
11
|
+
gem.summary = %q{Converts a configurable set of characters via a method added to the String class}
|
12
|
+
gem.homepage = "https://github.com/fortytools/unlaut"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unlaut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.3'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Axel Tetzlaff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Replace umlauts and other unwanted chars in strings
|
15
|
+
email:
|
16
|
+
- axel.tetzlaff@fortytools.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/unlaut.rb
|
27
|
+
- test/unlaut_test.rb
|
28
|
+
- unlaut.gemspec
|
29
|
+
homepage: https://github.com/fortytools/unlaut
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.23
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Converts a configurable set of characters via a method added to the String
|
53
|
+
class
|
54
|
+
test_files:
|
55
|
+
- test/unlaut_test.rb
|