accent-buster 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +74 -0
- data/Guardfile +14 -0
- data/README.md +58 -6
- data/Rakefile +1 -1
- data/accent-buster.gemspec +3 -8
- data/lib/accent-buster.rb +13 -2
- data/lib/accent-buster/buster.rb +43 -0
- data/lib/accent-buster/monkey_patch_string.rb +5 -0
- data/lib/accent-buster/string_extension.rb +5 -4
- data/lib/accent-buster/version.rb +1 -1
- data/spec/lib/accent_buster_spec.rb +22 -0
- data/spec/spec_helper.rb +3 -0
- metadata +49 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f68a3198636a19ba82aab1bbc92e6ee5d98d1ce6
|
4
|
+
data.tar.gz: e988a106de602aea667280496d366632b1f9ac73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a27cfd4602c219bc256aa6d43275c2be01f15d85d8fc93889b4040e4d46909c742b89971de9305f3e8ad20b7e10a64b94c83d2d0ecbcfa1566d179db12e7c2
|
7
|
+
data.tar.gz: dae409cf9194a1cfc841970a49e6512de9afc1d6cf0ff49b763889075fd8c2e1cf527f1a4769e1c8ea719ebc915b5a6eabceed161427a331245c9eebdfadd065
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
accent-buster
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
accent-buster (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
celluloid (0.16.0)
|
10
|
+
timers (~> 4.0.0)
|
11
|
+
coderay (1.1.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
ffi (1.9.8)
|
14
|
+
formatador (0.2.5)
|
15
|
+
guard (2.12.5)
|
16
|
+
formatador (>= 0.2.4)
|
17
|
+
listen (~> 2.7)
|
18
|
+
lumberjack (~> 1.0)
|
19
|
+
nenv (~> 0.1)
|
20
|
+
notiffany (~> 0.0)
|
21
|
+
pry (>= 0.9.12)
|
22
|
+
shellany (~> 0.0)
|
23
|
+
thor (>= 0.18.1)
|
24
|
+
guard-compat (1.2.1)
|
25
|
+
guard-rspec (4.5.0)
|
26
|
+
guard (~> 2.1)
|
27
|
+
guard-compat (~> 1.1)
|
28
|
+
rspec (>= 2.99.0, < 4.0)
|
29
|
+
hitimes (1.2.2)
|
30
|
+
listen (2.10.0)
|
31
|
+
celluloid (~> 0.16.0)
|
32
|
+
rb-fsevent (>= 0.9.3)
|
33
|
+
rb-inotify (>= 0.9)
|
34
|
+
lumberjack (1.0.9)
|
35
|
+
method_source (0.8.2)
|
36
|
+
nenv (0.2.0)
|
37
|
+
notiffany (0.0.6)
|
38
|
+
nenv (~> 0.1)
|
39
|
+
shellany (~> 0.0)
|
40
|
+
pry (0.10.1)
|
41
|
+
coderay (~> 1.1.0)
|
42
|
+
method_source (~> 0.8.1)
|
43
|
+
slop (~> 3.4)
|
44
|
+
rake (10.4.2)
|
45
|
+
rb-fsevent (0.9.4)
|
46
|
+
rb-inotify (0.9.5)
|
47
|
+
ffi (>= 0.5.0)
|
48
|
+
rspec (3.2.0)
|
49
|
+
rspec-core (~> 3.2.0)
|
50
|
+
rspec-expectations (~> 3.2.0)
|
51
|
+
rspec-mocks (~> 3.2.0)
|
52
|
+
rspec-core (3.2.3)
|
53
|
+
rspec-support (~> 3.2.0)
|
54
|
+
rspec-expectations (3.2.1)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.2.0)
|
57
|
+
rspec-mocks (3.2.1)
|
58
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
+
rspec-support (~> 3.2.0)
|
60
|
+
rspec-support (3.2.2)
|
61
|
+
shellany (0.0.1)
|
62
|
+
slop (3.6.0)
|
63
|
+
thor (0.19.1)
|
64
|
+
timers (4.0.1)
|
65
|
+
hitimes
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
ruby
|
69
|
+
|
70
|
+
DEPENDENCIES
|
71
|
+
accent-buster!
|
72
|
+
bundler (~> 1.0, >= 1.5.1)
|
73
|
+
guard-rspec (~> 4.5)
|
74
|
+
rake (~> 10.4, >= 10.4.2)
|
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# RSpec files
|
6
|
+
rspec = dsl.rspec
|
7
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
8
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
9
|
+
watch(rspec.spec_files)
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
ruby = dsl.ruby
|
13
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
14
|
+
end
|
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
# Accent Buster
|
1
|
+
# Accent Buster (2.0)
|
2
2
|
|
3
|
-
|
3
|
+
Extra methods do deal with diacritics (accent) in latin languages.
|
4
4
|
|
5
|
-
|
5
|
+
They replace diacritcs by their non-diacritic equivalents. Example: "ação" becomes "acao".
|
6
6
|
|
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
|
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 code all the time).
|
8
8
|
|
9
9
|
BTW, if you want to get really serious on that, the gem "UnicodeUtils" is a far better (and more complete) option. ^\_^
|
10
10
|
|
11
|
-
|
11
|
+
## Note on version 2.0
|
12
|
+
|
13
|
+
I gave up on the "Refinement" idea of the previous version. Reason? I use this A LOT and, for some (unconventional) cases, I had to make fancy maneuvers to be able to use it. Meh :p
|
14
|
+
|
15
|
+
The support for Refinement is still here, maybe I never remove it. However, I added 2 other usage options (explained below in "Usage").
|
12
16
|
|
13
17
|
## Installation
|
14
18
|
|
@@ -24,9 +28,56 @@ Or install it yourself as:
|
|
24
28
|
|
25
29
|
$ gem install accent-buster
|
26
30
|
|
27
|
-
## Usage
|
31
|
+
## Usage (plain object)
|
32
|
+
|
33
|
+
If you need a "no fluffy, no magic" version, this one is for you. Just a Plain Old Ruby Object`.tm`
|
28
34
|
|
29
35
|
```ruby
|
36
|
+
require 'accent-buster'
|
37
|
+
|
38
|
+
# Bust accents
|
39
|
+
AccentBuster::Buster.new('ação').bust # => 'acao'
|
40
|
+
|
41
|
+
# Bust accents (with include)
|
42
|
+
include AccentBuster
|
43
|
+
x = Buster.new('é você?')
|
44
|
+
x.bust # => x = 'e voce'
|
45
|
+
|
46
|
+
# Upcase
|
47
|
+
Buster.new('ação').up # => 'AÇÃO'
|
48
|
+
|
49
|
+
# Downcase
|
50
|
+
Buster.new('É VocÊ?').downcase # => 'é você?'
|
51
|
+
```
|
52
|
+
|
53
|
+
## Usage (monkey patch)
|
54
|
+
|
55
|
+
(#shame My favorite!)
|
56
|
+
|
57
|
+
Just one method added: String#buster. This should reduce the chance of name collision and it keeps the API clean and extensible.
|
58
|
+
|
59
|
+
If you are using it for applications, I recommend use it this way. If you are making a gem, avoid this.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require 'accent-buster/monkey_patch_string'
|
63
|
+
|
64
|
+
# Bust accents
|
65
|
+
'ação'.buster.bust # => 'acao'
|
66
|
+
|
67
|
+
# Upcase
|
68
|
+
'ação'.buster.up # => 'AÇÃO'
|
69
|
+
|
70
|
+
# Downcase
|
71
|
+
'É VocÊ?'.buster.down # => 'é você?'
|
72
|
+
```
|
73
|
+
|
74
|
+
## Usage (with refinements)
|
75
|
+
|
76
|
+
Safe, clean and "modern" :p
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'accent-buster'
|
80
|
+
|
30
81
|
# Refinements!
|
31
82
|
using AccentBuster::StringExtension
|
32
83
|
|
@@ -48,3 +99,4 @@ x.upcase!
|
|
48
99
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
50
101
|
5. Create new Pull Request
|
102
|
+
6. Wait, have a cake, enjoy!
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/accent-buster.gemspec
CHANGED
@@ -4,18 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'accent-buster/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
# We are using refinements
|
8
|
-
# Something wrong when trying to install
|
9
|
-
# using bundler =\
|
10
|
-
# Does not accept ruby 2.1 >_<
|
11
|
-
#spec.required_ruby_version = '>= 2.0'
|
12
|
-
|
13
7
|
spec.name = "accent-buster"
|
14
8
|
spec.version = AccentBuster::VERSION
|
15
9
|
spec.authors = ["Ronie Uliana"]
|
16
10
|
spec.email = ["ronie.uliana@gmail.com"]
|
17
11
|
spec.description = %q{Add "String#accent_buster" that replaces diacritics marks by their non-diacritic equivalents.}
|
18
|
-
spec.summary = %q{Add "String#accent_buster" that replaces diacritics marks by their non-diacritic equivalents. 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). This lib will have NO MORE than the very strictly necessary to replace diacritics
|
12
|
+
spec.summary = %q{Add "String#accent_buster" that replaces diacritics marks by their non-diacritic equivalents. 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). This lib will have NO MORE than the very strictly necessary to replace diacritics.}
|
19
13
|
spec.homepage = "http://github.com/ruliana/accent-buster"
|
20
14
|
spec.license = "MIT"
|
21
15
|
|
@@ -25,5 +19,6 @@ Gem::Specification.new do |spec|
|
|
25
19
|
spec.require_paths = ["lib"]
|
26
20
|
|
27
21
|
spec.add_development_dependency "bundler", "~> 1.0", ">= 1.5.1"
|
28
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.4", ">= 10.4.2"
|
23
|
+
spec.add_development_dependency "guard-rspec", "~> 4.5"
|
29
24
|
end
|
data/lib/accent-buster.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "accent-buster/version"
|
2
|
+
require "accent-buster/string_extension"
|
3
|
+
require "accent-buster/buster"
|
3
4
|
|
4
5
|
module AccentBuster
|
6
|
+
# Wrap an object to add accent wise (diacritic wise)
|
7
|
+
# methods.
|
8
|
+
#
|
9
|
+
# It works for latin languages only.
|
10
|
+
#
|
11
|
+
# @see Buster#bust
|
12
|
+
# @return [Buster] object with extra methods.
|
13
|
+
def buster
|
14
|
+
Buster.new(self)
|
15
|
+
end
|
5
16
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class AccentBuster::Buster
|
2
|
+
ACCENT_DOWNCASE = "áéíóúâêîôûäëïöüãõñç"
|
3
|
+
NO_ACCENT_DOWNCASE = "aeiouaeiouaeiouaonc"
|
4
|
+
ACCENT_UPCASE = "ÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ"
|
5
|
+
NO_ACCENT_UPCASE = "AEIOUAEIOUAEIOUAONC"
|
6
|
+
|
7
|
+
# Wrap an object to add accent wise (diacritic wise)
|
8
|
+
# methods.
|
9
|
+
#
|
10
|
+
# It works for latin languages only.
|
11
|
+
#
|
12
|
+
# @param a_string [#to_s]
|
13
|
+
def initialize(a_string)
|
14
|
+
@a_string = a_string.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
# Convert diacritics chars to their non-diacritic equivalents.
|
18
|
+
#
|
19
|
+
# "áéíóú âêîôû äëïöü ãõ ñç" => "aeiou aeiou aeiou ao nc"
|
20
|
+
#
|
21
|
+
# @return the string with diacritics removed.
|
22
|
+
def bust
|
23
|
+
@a_string.tr(ACCENT_DOWNCASE + ACCENT_UPCASE, NO_ACCENT_DOWNCASE + NO_ACCENT_UPCASE)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Upcase the string, correctly converting diacritcs.
|
27
|
+
#
|
28
|
+
# Example: "ótimo" => "ÓTIMO"
|
29
|
+
#
|
30
|
+
# @return the string upper case
|
31
|
+
def up
|
32
|
+
@a_string.tr(ACCENT_DOWNCASE, ACCENT_UPCASE).upcase
|
33
|
+
end
|
34
|
+
|
35
|
+
# Downcase the string, correctly converting diacritcs.
|
36
|
+
#
|
37
|
+
# Example: "ÓTIMO" => "ótimo"
|
38
|
+
#
|
39
|
+
# @return the string lower case
|
40
|
+
def down
|
41
|
+
@a_string.tr(ACCENT_UPCASE, ACCENT_DOWNCASE).downcase
|
42
|
+
end
|
43
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module AccentBuster::StringExtension
|
2
|
+
# @deprecated Use [Buster] or include [AccentBuster] to use #buster method
|
2
3
|
refine String do
|
3
|
-
ACCENT_DOWNCASE =
|
4
|
-
NO_ACCENT_DOWNCASE =
|
5
|
-
ACCENT_UPCASE =
|
6
|
-
NO_ACCENT_UPCASE =
|
4
|
+
ACCENT_DOWNCASE = "áéíóúâêîôûäëïöüãõñç"
|
5
|
+
NO_ACCENT_DOWNCASE = "aeiouaeiouaeiouaonc"
|
6
|
+
ACCENT_UPCASE = "ÁÉÍÓÚÂÊÎÔÛÄËÏÖÜÃÕÑÇ"
|
7
|
+
NO_ACCENT_UPCASE = "AEIOUAEIOUAEIOUAONC"
|
7
8
|
|
8
9
|
# Convert diacritics chars to their non-diacritic equivalents.
|
9
10
|
#
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AccentBuster do
|
4
|
+
let(:subject) { "açÃo!".extend(AccentBuster) }
|
5
|
+
describe "#accent_buster" do
|
6
|
+
it 'replaces "açÃo!" by "acAo!"' do
|
7
|
+
expect(subject.buster.bust).to eq "acAo!"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#accent_buster(:up)" do
|
12
|
+
it 'upcases "açÃo!" to "AÇÃO!"' do
|
13
|
+
expect(subject.buster.up).to eq "AÇÃO!"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#accent_buster(:down)" do
|
18
|
+
it 'upcases "açÃo!" to "ação!"' do
|
19
|
+
expect(subject.buster.down).to eq "ação!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,49 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accent-buster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2015-05-15 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.0'
|
20
|
-
- -
|
20
|
+
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.5.1
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.0'
|
30
|
-
- -
|
30
|
+
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.5.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '10.4'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 10.4.2
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.4'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 10.4.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: guard-rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '4.5'
|
40
60
|
type: :development
|
41
61
|
prerelease: false
|
42
62
|
version_requirements: !ruby/object:Gem::Requirement
|
43
63
|
requirements:
|
44
|
-
- -
|
64
|
+
- - "~>"
|
45
65
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
66
|
+
version: '4.5'
|
47
67
|
description: Add "String#accent_buster" that replaces diacritics marks by their non-diacritic
|
48
68
|
equivalents.
|
49
69
|
email:
|
@@ -52,15 +72,23 @@ executables: []
|
|
52
72
|
extensions: []
|
53
73
|
extra_rdoc_files: []
|
54
74
|
files:
|
55
|
-
- .gitignore
|
75
|
+
- ".gitignore"
|
76
|
+
- ".ruby-gemset"
|
77
|
+
- ".ruby-version"
|
56
78
|
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- Guardfile
|
57
81
|
- LICENSE
|
58
82
|
- README.md
|
59
83
|
- Rakefile
|
60
84
|
- accent-buster.gemspec
|
61
85
|
- lib/accent-buster.rb
|
86
|
+
- lib/accent-buster/buster.rb
|
87
|
+
- lib/accent-buster/monkey_patch_string.rb
|
62
88
|
- lib/accent-buster/string_extension.rb
|
63
89
|
- lib/accent-buster/version.rb
|
90
|
+
- spec/lib/accent_buster_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
64
92
|
homepage: http://github.com/ruliana/accent-buster
|
65
93
|
licenses:
|
66
94
|
- MIT
|
@@ -71,23 +99,23 @@ require_paths:
|
|
71
99
|
- lib
|
72
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
101
|
requirements:
|
74
|
-
- -
|
102
|
+
- - ">="
|
75
103
|
- !ruby/object:Gem::Version
|
76
104
|
version: '0'
|
77
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
106
|
requirements:
|
79
|
-
- -
|
107
|
+
- - ">="
|
80
108
|
- !ruby/object:Gem::Version
|
81
109
|
version: '0'
|
82
110
|
requirements: []
|
83
111
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.4.6
|
85
113
|
signing_key:
|
86
114
|
specification_version: 4
|
87
|
-
summary:
|
88
|
-
equivalents. I made it because I don'
|
89
|
-
everytime I need that (also, I'
|
90
|
-
This lib will have NO MORE than the very strictly necessary to replace diacritics
|
91
|
-
|
92
|
-
|
93
|
-
|
115
|
+
summary: Add "String#accent_buster" that replaces diacritics marks by their non-diacritic
|
116
|
+
equivalents. I made it because I don't want to add "ActiveSupport" to the projects
|
117
|
+
everytime I need that (also, I'm too lazy to type the same thing all the time).
|
118
|
+
This lib will have NO MORE than the very strictly necessary to replace diacritics.
|
119
|
+
test_files:
|
120
|
+
- spec/lib/accent_buster_spec.rb
|
121
|
+
- spec/spec_helper.rb
|