normalizacion 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f69dea95abfbf1d5047b21ca16a98c3427c51ef
4
+ data.tar.gz: 7699754c365cc3237e34c5d934b83a2529eac08f
5
+ SHA512:
6
+ metadata.gz: 5dbd571d3cf96839aee18635dc7cb9cb0c98e94aaaa6382624261140d0c1e27c3adc022f7c36b843b29a2fd61b9b9bd1c11a75c4bc2f90fff53fa35ca3c4136d
7
+ data.tar.gz: bda79b551263c055740956e67d074e5d29f4dfb0653908607d379e59beebf0cea1d69b3d6623d3baef7a1359ffb5c1fe3ca40346f5f7da4c2a2bdba8c31e0f46
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ normalizacion
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.9
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.9
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in string_normalizr.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2010, Carsten Zimmermann
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of the original author / copyright holder nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Normalizacion [![Build Status](https://travis-ci.org/carpodaster/normalizacion.svg?branch=master)](https://travis-ci.org/carpodaster/normalizacion)
2
+
3
+ This gem provides a [Refinement](http://ruby-doc.org/core-2.1.1/doc/syntax/refinements_rdoc.html) for the `String` class. It adds `String#normalize` which transliterates non-ASCII characters using a static collation table. It also replaces whitespaces with `-` and optionally downcases the string value.
4
+
5
+ It is very similar to what `ActiveSupport`'s `#parameterize` does, only more customizable (and without depending on ActiveSupport).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'normalizacion'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install normalizacion
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class YourClass
25
+ using Normalizacion
26
+
27
+ def to_s
28
+ "Schöneberger Straße"
29
+ end
30
+ end
31
+
32
+ YourClass.new.to_s # => "Schoenberger-Strasse"
33
+ ```
34
+
35
+ ## .plan
36
+ * support custom collation hash
37
+ * support more special chars by default
38
+ * handle punctuation marks
39
+
40
+ ## Changelog
41
+ ### v1.0.0
42
+ * Uses Ruby 2.1 idioms: Keyword Arguments and Refinments
43
+ * Renamed gem
44
+
45
+ #### v0.3.0
46
+ * Added `#normalize!` for in-place normalization
47
+ * Adds downcase option
48
+
49
+ ### v0.2.0
50
+ * Normalization can now be customized via an options hash.
51
+
52
+ ---
53
+
54
+ Copyright (c) 2010-2016 Carsten Zimmermann, released under a BSD-type license
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new("test") do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "string_normalizr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,93 @@
1
+ module Normalizacion
2
+
3
+ refine String do
4
+
5
+ COLLATION = {
6
+ 'Ä' => 'Ae',
7
+ 'Æ' => 'Ae',
8
+ 'Å' => 'A',
9
+ 'À' => 'A',
10
+ 'Á' => 'A',
11
+ 'Â' => 'A',
12
+ 'Ç' => 'C',
13
+ 'È' => "E",
14
+ 'É' => "E",
15
+ 'Ê' => "E",
16
+ 'Ë' => 'E',
17
+ 'Í' => 'I',
18
+ 'Ì' => 'I',
19
+ 'Î' => 'I',
20
+ 'Ï' => 'I',
21
+ 'Ñ' => 'N',
22
+ 'Ö' => 'Oe',
23
+ 'Œ' => 'Oe',
24
+ 'Ø' => 'O',
25
+ 'Ô' => 'O',
26
+ 'Ó' => 'O',
27
+ 'Ò' => 'O',
28
+ 'Ü' => 'Ue',
29
+ 'Ú' => 'U',
30
+ 'Ù' => 'U',
31
+ 'Ÿ' => 'Y',
32
+ 'ä' => 'ae',
33
+ 'æ' => 'ae',
34
+ 'å' => 'a',
35
+ 'à' => 'a',
36
+ 'á' => 'a',
37
+ 'â' => 'a',
38
+ 'ç' => 'c',
39
+ 'è' => 'e',
40
+ 'é' => 'e',
41
+ 'ê' => 'e',
42
+ 'ë' => 'e',
43
+ 'í' => 'i',
44
+ 'ì' => 'i',
45
+ 'î' => 'i',
46
+ 'ï' => 'i',
47
+ 'ñ' => 'n',
48
+ 'ö' => 'oe',
49
+ 'œ' => 'oe',
50
+ 'ø' => 'o',
51
+ 'ô' => 'o',
52
+ 'ó' => 'o',
53
+ 'ò' => 'o',
54
+ 'ü' => 'ue',
55
+ 'ú' => 'u',
56
+ 'ù' => 'u',
57
+ 'ÿ' => 'y',
58
+ 'ß' => 'ss',
59
+ }
60
+
61
+ # Returns a new String based on pre-defined normalization rules
62
+ #
63
+ # == Available keyword options
64
+ # * <tt>:downcase</tt> - convert to lower case (true|false, default: false)
65
+ # * <tt>:strip</tt> - trim leading and trailing whitespaces (true|false, default: true)
66
+ # * <tt>:replace_whitespaces</tt> - replace whitespaces within the string with +str+
67
+ # or set to +false+ to leave whitespaces alone. Makes little
68
+ # sense w/o :strip => true (str|false, default: "-")
69
+ #
70
+ # == Examples
71
+ # "This is án exåmple".normalize
72
+ # => "This-is-an-example
73
+ #
74
+ # "Tëst string with träiling whitespaces ".normalize(:replace_whitespaces => false)
75
+ # => "Test string with traeiling whitespaces"
76
+ #
77
+ def normalize(downcase: false, strip: true, replace_whitespaces: '-')
78
+ n_str = Normalizacion::COLLATION.inject(dup) {|str, (collate_from, collate_to)| str.gsub(collate_from, collate_to)}
79
+ n_str.strip! if strip
80
+ n_str.downcase! if downcase
81
+ n_str.gsub!(/\s+/, replace_whitespaces) if replace_whitespaces
82
+ n_str
83
+ end
84
+
85
+ # Performs the changes of Normalizacion::(String)#normalize in place,
86
+ # returning the new string.
87
+ #
88
+ # See #normalize for the optional parameter hash.
89
+ def normalize!(*args)
90
+ replace normalize(*args)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module Normalizacion
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'normalizacion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "normalizacion"
8
+ spec.version = Normalizacion::VERSION
9
+ spec.authors = ["Carsten Zimmermann"]
10
+ spec.email = ["cz@aegisnet.de"]
11
+
12
+ spec.summary = %q{Provides normalization/transliteration functionality for Strings using Ruby Refinements}
13
+ spec.homepage = "http://github.com/carpodaster/string_normalizr"
14
+ spec.license = "BSD"
15
+
16
+ spec.required_ruby_version = '>= 2.1'
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: normalizacion
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Zimmermann
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - cz@aegisnet.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-gemset"
50
+ - ".ruby-version"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/normalizacion.rb
59
+ - lib/normalizacion/version.rb
60
+ - normalizacion.gemspec
61
+ homepage: http://github.com/carpodaster/string_normalizr
62
+ licenses:
63
+ - BSD
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2.1'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.8
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Provides normalization/transliteration functionality for Strings using Ruby
85
+ Refinements
86
+ test_files: []