accentless 0.1.2 → 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec6d558d5e9eafe007d0af3fed6b225260750f87
4
+ data.tar.gz: 25eccfd3b4f9dd69b8a1e846e380bf053bab0ebf
5
+ SHA512:
6
+ metadata.gz: 3af095d1af8f1aa0fbbf13606431bb2ce211c0e98bbd0a9ece3572b84ea1b344d37a04042a32ed648de3baacfbdee364eddf965c1803c7d0c89eac7d97ffcc76
7
+ data.tar.gz: 49516a953c6eec066111f59cac105f2b9f24f5ebbafbfeeb9a2064260639224a3c79d5e93ecf9c330acee2974a039b99b270c6a59757096a21f08a64d4741d35
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.1.2
3
+ script: rspec spec
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in accentless.gemspec
4
4
  gemspec
@@ -0,0 +1,52 @@
1
+ # Accentless
2
+
3
+ Remove accents from `String`s easily, using new Ruby 2.x `Refinements`.
4
+
5
+ ## Status
6
+ [![Build Status](https://travis-ci.org/lucasas/accentless.svg?branch=master)](http://travis-ci.org/lucasas/accentless?branch=master)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'accentless'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install accentless
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'accentless'
26
+
27
+ class Word
28
+ using Accentless
29
+
30
+ def initialize(word)
31
+ @word = word
32
+ end
33
+
34
+ def value
35
+ # you can use String#accentless! method which
36
+ # modifies original String
37
+ @word.accentless
38
+ end
39
+ end
40
+
41
+ Word.new("São Paulo").value #=> Sao Paulo
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ You can contribute easily too:
47
+
48
+ 1. Fork it ( http://github.com/lucasas/accentless/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -7,9 +7,9 @@ Gem::Specification.new do |s|
7
7
  s.version = Accentless::VERSION
8
8
  s.authors = ["Lucas Souza"]
9
9
  s.email = ["lucasas@gmail.com"]
10
- s.homepage = ""
11
- s.summary = ""
12
- s.description = ""
10
+ s.homepage = "http://github.com/lucasas/accentless/"
11
+ s.summary = %q{Rubygem to removing accents}
12
+ s.description = %q{Rubygem to removing accents.}
13
13
 
14
14
  s.rubyforge_project = "accentless"
15
15
 
@@ -1,4 +1,4 @@
1
- class String
1
+ module Accentless
2
2
  ACCENTS_MAPPING = {
3
3
  'E' => [200,201,202,203],
4
4
  'e' => [232,233,234,235,7869],
@@ -22,31 +22,24 @@ class String
22
22
  'oe' => [189]
23
23
  }
24
24
 
25
- def remove_accents
26
- str = String.new(self)
27
- String::ACCENTS_MAPPING.each {|letter,accents|
28
- packed = accents.pack('U*')
29
- rxp = Regexp.new("[#{packed}]", nil)
30
- str.gsub!(rxp, letter)
31
- }
32
-
33
- str
34
- end
25
+ refine String do
26
+ def accentless(string = String.new(self))
27
+ string.tap do |s|
28
+ ACCENTS_MAPPING.each { |letter, accents| replace(s, letter, accents) }
29
+ end
30
+ end
35
31
 
36
- def remove_ponctuation
37
- warn "[DEPRECATION] Method renamed to remove_punctuation"
38
- remove_punctuation
39
- end
32
+ def accentless!
33
+ accentless(self)
34
+ end
40
35
 
41
- def remove_punctuation
42
- str = String.new(self)
43
- str.gsub!(/[^\w\s]/,"")
44
- str
45
- end
36
+ private
46
37
 
47
- def only_text
48
- str = String.new(self)
49
- str.remove_accents.remove_punctuation
38
+ def replace(string, letter, accents)
39
+ packed = accents.pack('U*')
40
+ regex = Regexp.new("[#{packed}]", nil)
41
+ string.gsub!(regex, letter)
42
+ end
50
43
  end
51
44
  end
52
45
 
@@ -1,3 +1,3 @@
1
1
  module Accentless
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,34 +1,28 @@
1
- # coding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  describe String do
6
- it "should remove string accents" do
7
- "São Paulo".remove_accents.should == "Sao Paulo"
8
- end
9
-
10
- it "should remove the most annoying Hungarian accents" do
11
- "fejlődő".remove_accents.should == "fejlodo"
12
- "FEJLŐDŐ".remove_accents.should == "FEJLODO"
4
+ specify { expect(Word.new("São Paulo").accentless).to eq "Sao Paulo" }
5
+ specify { expect(Word.new("Tẽst").accentless).to eq "Test" }
13
6
 
14
- "fű".remove_accents.should == "fu"
15
- "FŰ".remove_accents.should == "FU"
7
+ it "does not change original string" do
8
+ word = Word.new("São Paulo")
9
+ expect(word.accentless).to eq "Sao Paulo"
10
+ expect(word.value).to eq "São Paulo"
16
11
  end
17
12
 
18
- it "should remove letter 'e' with tilde" do
19
- "Tẽst".remove_accents.should == "Test"
13
+ context "hungarian accents" do
14
+ specify { expect(Word.new("fejlődő").accentless).to eq "fejlodo" }
15
+ specify { expect(Word.new("FEJLŐDŐ").accentless).to eq "FEJLODO" }
16
+ specify { expect(Word.new("fű").accentless).to eq "fu" }
17
+ specify { expect(Word.new("FŰ").accentless).to eq "FU" }
20
18
  end
21
19
 
22
- describe "remove_punctuation" do
23
- it "should remove especial caracters" do
24
- "Testing: all! punctuation?.,'¿! should be removed".remove_punctuation.should == "Testing all punctuation should be removed"
25
- end
26
- end
20
+ context "accentless!" do
21
+ let(:word) { Word.new("São Paulo") }
27
22
 
28
- describe "only_text" do
29
- it "should remove accents and punctuation" do
30
- "Testing: lâmpadas mágicas não existem!".only_text.should == "Testing lampadas magicas nao existem"
23
+ it "changes original string" do
24
+ expect(word.accentless!).to eq "Sao Paulo"
25
+ expect(word.value).to eq "Sao Paulo"
31
26
  end
32
27
  end
33
-
34
28
  end
@@ -6,3 +6,19 @@ RSpec.configure do |config|
6
6
  config.mock_with :rspec
7
7
  end
8
8
 
9
+ class Word
10
+ attr_reader :value
11
+ using Accentless
12
+
13
+ def initialize(value)
14
+ @value = value
15
+ end
16
+
17
+ def accentless
18
+ @value.accentless
19
+ end
20
+
21
+ def accentless!
22
+ @value.accentless!
23
+ end
24
+ end
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accentless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Lucas Souza
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.6.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.6.0
30
- description: ''
27
+ description: Rubygem to removing accents.
31
28
  email:
32
29
  - lucasas@gmail.com
33
30
  executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .rspec
39
- - .rvmrc
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".ruby-version"
37
+ - ".rvmrc"
38
+ - ".travis.yml"
40
39
  - Gemfile
41
40
  - Gemfile.lock
42
41
  - README
42
+ - README.md
43
43
  - Rakefile
44
44
  - accentless-0.1.0.gem
45
45
  - accentless.gemspec
@@ -48,30 +48,29 @@ files:
48
48
  - lib/accentless/version.rb
49
49
  - spec/accentless/extend_string_spec.rb
50
50
  - spec/spec_helper.rb
51
- homepage: ''
51
+ homepage: http://github.com/lucasas/accentless/
52
52
  licenses: []
53
+ metadata: {}
53
54
  post_install_message:
54
55
  rdoc_options: []
55
56
  require_paths:
56
57
  - lib
57
58
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
59
  requirements:
60
- - - ! '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
64
  requirements:
66
- - - ! '>='
65
+ - - ">="
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
69
68
  requirements: []
70
69
  rubyforge_project: accentless
71
- rubygems_version: 1.8.24
70
+ rubygems_version: 2.3.0
72
71
  signing_key:
73
- specification_version: 3
74
- summary: ''
72
+ specification_version: 4
73
+ summary: Rubygem to removing accents
75
74
  test_files:
76
75
  - spec/accentless/extend_string_spec.rb
77
76
  - spec/spec_helper.rb