core_extended 0.0.1
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.
- data/.coveralls.yml +2 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +10 -0
- data/extension.gemspec +26 -0
- data/lib/core_extended.rb +1 -0
- data/lib/core_extended/string.rb +52 -0
- data/lib/core_extended/version.rb +3 -0
- data/spec/coverage_helper.rb +8 -0
- data/spec/minitest_helper.rb +9 -0
- data/spec/string_spec.rb +74 -0
- metadata +144 -0
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Gabriel Naiman
|
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,33 @@
|
|
1
|
+
# core_extended
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/core_extended)
|
4
|
+
[](https://travis-ci.org/gabynaiman/core_extended)
|
5
|
+
[](https://coveralls.io/r/gabynaiman/core_extended?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gabynaiman/core_extended)
|
7
|
+
[](https://gemnasium.com/gabynaiman/core_extended)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'core_extended'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install core_extended
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/extension.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'core_extended/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "core_extended"
|
8
|
+
spec.version = CoreExtended::VERSION
|
9
|
+
spec.authors = ["Gabriel Naiman"]
|
10
|
+
spec.email = ["gabynaiman@gmail.com"]
|
11
|
+
spec.description = 'Ruby core extensions'
|
12
|
+
spec.summary = 'Ruby core extensions'
|
13
|
+
spec.homepage = "https://github.com/gabynaiman/core_extended"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest", "~> 4.7"
|
24
|
+
spec.add_development_dependency "turn", "~> 0.9"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/#{File.basename(__FILE__, '.rb')}/*.rb"].each { |file| require file }
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class String
|
3
|
+
|
4
|
+
ACCENTS_MAPPING = [
|
5
|
+
{letter: 'A', upcase: 'ÁÀÄÂ', downcase: 'áàäâ'},
|
6
|
+
{letter: 'E', upcase: 'ÉÈËÊ', downcase: 'éèëê'},
|
7
|
+
{letter: 'I', upcase: 'ÍÌÏÎ', downcase: 'íìïî'},
|
8
|
+
{letter: 'O', upcase: 'ÓÒÖÔ', downcase: 'óòöô'},
|
9
|
+
{letter: 'U', upcase: 'ÚÙÜÛ', downcase: 'úùüû'}
|
10
|
+
]
|
11
|
+
|
12
|
+
alias_method :upcase_ignoring_accents!, :upcase!
|
13
|
+
def upcase!
|
14
|
+
ACCENTS_MAPPING.each { |map| tr! map[:downcase], map[:upcase] }
|
15
|
+
upcase_ignoring_accents!
|
16
|
+
end
|
17
|
+
|
18
|
+
def upcase
|
19
|
+
self.dup.upcase!
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :downcase_ignoring_accents!, :downcase!
|
23
|
+
def downcase!
|
24
|
+
ACCENTS_MAPPING.each { |map| tr! map[:upcase], map[:downcase] }
|
25
|
+
downcase_ignoring_accents!
|
26
|
+
end
|
27
|
+
|
28
|
+
def downcase
|
29
|
+
self.dup.downcase!
|
30
|
+
end
|
31
|
+
|
32
|
+
def unaccented!
|
33
|
+
ACCENTS_MAPPING.each do |map|
|
34
|
+
tr! map[:upcase], map[:letter]
|
35
|
+
tr! map[:downcase], map[:letter].downcase
|
36
|
+
end
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def unaccented
|
41
|
+
self.dup.unaccented!
|
42
|
+
end
|
43
|
+
|
44
|
+
def normalized!
|
45
|
+
self.unaccented!.downcase!
|
46
|
+
end
|
47
|
+
|
48
|
+
def normalized
|
49
|
+
self.dup.normalized!
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'minitest_helper'
|
3
|
+
|
4
|
+
describe String do
|
5
|
+
|
6
|
+
describe 'Upcase' do
|
7
|
+
|
8
|
+
it 'With accents' do
|
9
|
+
'áèïôu'.upcase.must_equal 'ÁÈÏÔU'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Without accents' do
|
13
|
+
'aEiOu'.upcase.must_equal 'AEIOU'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'Change itself' do
|
17
|
+
string = 'áèiÖU'
|
18
|
+
string.upcase!.must_equal 'ÁÈIÖU'
|
19
|
+
string.must_equal 'ÁÈIÖU'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'Downcase' do
|
25
|
+
|
26
|
+
it 'With accents' do
|
27
|
+
'ÁÈÏÔU'.downcase.must_equal 'áèïôu'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Without accents' do
|
31
|
+
'aEiOu'.downcase.must_equal 'aeiou'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'Change itself' do
|
35
|
+
string = 'ÁÈIöu'
|
36
|
+
string.downcase!.must_equal 'áèiöu'
|
37
|
+
string.must_equal 'áèiöu'
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'Unaccented' do
|
43
|
+
|
44
|
+
it 'Transform keeping case' do
|
45
|
+
string = 'Estas son mís létras MÁL acentúadäs y répetidâs íntëntândö ûtîlïzàr tôdas las varïantês'
|
46
|
+
string.unaccented.must_equal 'Estas son mis letras MAL acentuadas y repetidas intentando utilizar todas las variantes'
|
47
|
+
string.must_equal 'Estas son mís létras MÁL acentúadäs y répetidâs íntëntândö ûtîlïzàr tôdas las varïantês'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'Change itself' do
|
51
|
+
string = 'áëÌôÛ'
|
52
|
+
string.unaccented!.must_equal 'aeIoU'
|
53
|
+
string.must_equal 'aeIoU'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'Normalized' do
|
59
|
+
|
60
|
+
it 'Case and accents' do
|
61
|
+
string = 'LétterS wÏth DifFèrent case ÂND Äccents'
|
62
|
+
string.normalized.must_equal 'letters with different case and accents'
|
63
|
+
string.must_equal 'LétterS wÏth DifFèrent case ÂND Äccents'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'Change itself' do
|
67
|
+
string = 'SámPlÊ'
|
68
|
+
string.normalized!.must_equal 'sample'
|
69
|
+
string.must_equal 'sample'
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: core_extended
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriel Naiman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: minitest
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: turn
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.9'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Ruby core extensions
|
95
|
+
email:
|
96
|
+
- gabynaiman@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .coveralls.yml
|
102
|
+
- .gitignore
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- extension.gemspec
|
109
|
+
- lib/core_extended.rb
|
110
|
+
- lib/core_extended/string.rb
|
111
|
+
- lib/core_extended/version.rb
|
112
|
+
- spec/coverage_helper.rb
|
113
|
+
- spec/minitest_helper.rb
|
114
|
+
- spec/string_spec.rb
|
115
|
+
homepage: https://github.com/gabynaiman/core_extended
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.24
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Ruby core extensions
|
140
|
+
test_files:
|
141
|
+
- spec/coverage_helper.rb
|
142
|
+
- spec/minitest_helper.rb
|
143
|
+
- spec/string_spec.rb
|
144
|
+
has_rdoc:
|