diacritics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 900204c7d54154241404e0e7a53e0dd0e2a27f2a
4
+ data.tar.gz: b1bf104411b8ceae95c445a85f5a8c589307ad4d
5
+ SHA512:
6
+ metadata.gz: 7fb9ad4389ca32ccec7c55d6eec830161e32bab8264718d3a6494dfc1adddec387d335031c0600a108468a99a5e9fd70c2bf0bed368e074dd458470b2de9955a
7
+ data.tar.gz: 48d93db86a66c5dc7622c67493ece4462f05f9c657f3ce10e590f8a737aa5931aa9b9ed5d9c188885c9f65dbf3220c6afc34ebeaaeff651f09b80ece3baf493b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ diacritics
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in diacritics.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'coveralls', require: false
8
+ gem 'rspec'
9
+ gem 'reek'
10
+ gem 'guard'
11
+ gem 'guard-bundler'
12
+ gem 'guard-rspec'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) do |array|
9
+ name = array.last
10
+ "spec/#{name}_spec.rb"
11
+ end
12
+ watch('spec/spec_helper.rb') { "spec" }
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fractal Soft
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,50 @@
1
+ # Diacritics [![Gem Version](https://badge.fury.io/rb/diacritics.png)](http://badge.fury.io/rb/diacritics) [![Build Status](https://travis-ci.org/fractalsoft/diacritics.png)](https://travis-ci.org/fractalsoft/diacritics) [![Dependency Status](https://gemnasium.com/fractalsoft/diacritics.png)](https://gemnasium.com/fractalsoft/diacritics) [![Coverage Status](https://coveralls.io/repos/fractalsoft/diacritics/badge.png)](https://coveralls.io/r/fractalsoft/diacritics)
2
+ [![endorse](https://api.coderwall.com/torrocus/endorsecount.png)](https://coderwall.com/torrocus)
3
+
4
+ Diacritics is a gem which support downcase, upcase and permanent link with diacritical characters.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'diacritics'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install diacritics
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ Diacritics::downcase(text)
24
+ Diacritics::upcase(text)
25
+ Diacritics::permanent(text)
26
+ ```
27
+
28
+ You can include methods into String class:
29
+
30
+ ```ruby
31
+ class String
32
+ include Diacritics::String
33
+ end
34
+ ```
35
+
36
+ and use
37
+
38
+ ```ruby
39
+ string.diacritics_downcase
40
+ string.diacritics_upcase
41
+ string.permanent_link
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'diacritics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "diacritics"
8
+ spec.version = Diacritics::VERSION
9
+ spec.authors = ["Aleksander Malaszkiewicz"]
10
+ spec.email = ["alek@fractalsoft.org"]
11
+ spec.summary = %q{Support diacritics}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,137 @@
1
+ # encoding: utf-8
2
+ module Diacritics
3
+ private
4
+ # Characters from many alphabets
5
+ class Alphabet
6
+ attr_reader :regexp, :hash
7
+
8
+ def initialize
9
+ @downcase, @upcase, @permanent = [], [], []
10
+ prepare_alphabet
11
+ @hash, @regexp = prepare_hash, prepare_regexp
12
+ end
13
+
14
+ private
15
+ def prepare_alphabet
16
+ data.each_pair do |language, hash|
17
+ @downcase += hash[:downcase]
18
+ @upcase += hash[:upcase]
19
+ @permanent += hash[:permanent]
20
+ end
21
+ end
22
+
23
+ def prepare_hash
24
+ klass = Diacritics::Alphabet
25
+ hash = klass.hashed(@downcase, @upcase)
26
+ one = klass.hashed(@downcase, @permanent)
27
+ two = klass.hashed(@upcase, @permanent)
28
+ {
29
+ downcase: hash.invert,
30
+ upcase: hash,
31
+ permanent: one.merge(two),
32
+ }
33
+ end
34
+
35
+ def prepare_regexp
36
+ downcase, upcase = @upcase.join, @downcase.join
37
+ permanent = (@downcase + @upcase).uniq.join
38
+ {
39
+ downcase: /[#{downcase}]/,
40
+ upcase: /[#{upcase}]/,
41
+ permanent: /[#{permanent}]/,
42
+ }
43
+ end
44
+
45
+ # Creates a hash from two arrays
46
+ #
47
+ # ["a", "b"], ["A", "B"] #=> {"a" => "A", "b" => "B"}
48
+ def self.hashed(one, two)
49
+ hash = {}
50
+ [one, two].transpose.each { |key, value| hash[key] = value }
51
+ hash
52
+ end
53
+
54
+ def data
55
+ {
56
+ en: { # English
57
+ downcase: [' ', '?', '.', ','],
58
+ upcase: [' ', '?', '.', ','],
59
+ permanent: ['-', '', '', ''],
60
+ },
61
+ de: { # German
62
+ downcase: %w[ä ö ü ß],
63
+ upcase: %w[Ä Ö Ü ẞ],
64
+ permanent: %w[ae oe ue ss]
65
+ },
66
+ pl: { # Polish
67
+ downcase: %w[ą ć ę ł ń ó ś ż ź],
68
+ upcase: %w[Ą Ć Ę Ł Ń Ó Ś Ż Ź],
69
+ permanent: %w[a c e l n o s z z]
70
+ },
71
+ cs: { # Czech [Ď, Ě, Ň, Ť, Ů, Ú, Û]
72
+ downcase: %w[á č í ř š ý ž],
73
+ upcase: %w[Á Č Í Ř Š Ý Ž],
74
+ permanent: %w[a c i r s y z]
75
+ },
76
+ fr: { # French [Œ, Ÿ, Î, Ï]
77
+ downcase: %w[à é è ê ô],
78
+ upcase: %w[À É È Ê Ô],
79
+ permanent: %w[a e e e o]
80
+ },
81
+ it: { # Italian
82
+ downcase: %w[ì ù ò],
83
+ upcase: %w[Ì Ù Ò],
84
+ permanent: %w[i u o]
85
+ },
86
+ eo: { # Esperanto
87
+ downcase: %w[ĉ ĝ ĥ ĵ ŝ ŭ],
88
+ upcase: %w[Ĉ Ĝ Ĥ Ĵ Ŝ Ŭ],
89
+ permanent: %w[c g h j s u]
90
+ },
91
+ is: { # Iceland
92
+ downcase: %w[ð þ],
93
+ upcase: %w[Ð Þ],
94
+ permanent: %w[d p]
95
+ },
96
+ pt: { # Portugal [Â]
97
+ downcase: %w[ã ç],
98
+ upcase: %w[Ã Ç],
99
+ permanent: %w[a c]
100
+ },
101
+ sp: { # Spanish
102
+ downcase: ['¿'],
103
+ upcase: ['¿'],
104
+ permanent: ['']
105
+ },
106
+ hu: { # Hungarian
107
+ downcase: %w[ő],
108
+ upcase: %w[Ő],
109
+ permanent: %w[oe]
110
+ },
111
+ nn: { # Norwegian
112
+ downcase: %w[æ å],
113
+ upcase: %w[Æ Å],
114
+ permanent: %w[ae a]
115
+ },
116
+ ru: { # Russian [Щ, Ъ, Э]
117
+ downcase: %w[
118
+ а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш ы ь ю я
119
+ ],
120
+ upcase: %w[
121
+ А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Ы Ь Ю Я
122
+ ],
123
+ permanent: %w[
124
+ а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш ы ь ю я
125
+ ]
126
+ },
127
+ gr: { # Greek [Β, Μ, Χ, Ω, Ή, Ύ, Ώ, ΐ, ΰ, Ϊ, Ϋ]
128
+ downcase: %w[α ά γ δ ε έ ζ η θ ι ί κ λ μ ν ξ ο ό π ρ σ τ υ φ ψ],
129
+ upcase: %w[Α Ά Γ Δ Ε Έ Ζ Η Θ Ι Ί Κ Λ Μ Ν Ξ Ο Ό Π Ρ Σ Τ Υ Φ Ψ],
130
+ permanent: %w[
131
+ a a g d e e z e th i i k l m n x o o p r s t y ph ps
132
+ ]
133
+ }
134
+ }
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ module Diacritics
3
+ # Downcase or upcase with diacritics support
4
+ class Cases
5
+ def self.instance
6
+ @instance ||= new
7
+ end
8
+
9
+ def initialize
10
+ @alphabet = Diacritics::Alphabet.new
11
+ @hash, @regexp = @alphabet.hash, @alphabet.regexp
12
+ end
13
+
14
+ def downcase(text)
15
+ text.downcase.gsub @regexp[:downcase], @hash[:downcase]
16
+ end
17
+
18
+ def upcase(text)
19
+ text.upcase.gsub @regexp[:upcase], @hash[:upcase]
20
+ end
21
+
22
+ def permanent(text)
23
+ text.downcase.gsub @regexp[:permanent], @hash[:permanent]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ class String
3
+ alias_method :old_downcase, :downcase
4
+ alias_method :old_upcase, :upcase
5
+ end
6
+
7
+ module Diacritics
8
+ module String
9
+ def diacritics_downcase
10
+ Diacritics::Cases.instance.downcase self
11
+ end
12
+
13
+ def diacritics_upcase
14
+ Diacritics::Cases.instance.upcase self
15
+ end
16
+
17
+ def permanent_link
18
+ Diacritics::Cases.instance.permanent self
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Diacritics
2
+ VERSION = "0.0.1"
3
+ end
data/lib/diacritics.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "diacritics/alphabet"
2
+ require "diacritics/cases"
3
+ require "diacritics/string"
4
+ require "diacritics/version"
5
+
6
+ module Diacritics
7
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,254 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Diacritics::Cases do
5
+ context "#downcase, #upcase, #permanent" do
6
+ subject { Diacritics::Cases.instance }
7
+
8
+ [
9
+ { # English
10
+ text: "Will will Will will Will's will to Will?",
11
+ lower: "will will will will will's will to will?",
12
+ upper: "WILL WILL WILL WILL WILL'S WILL TO WILL?",
13
+ permanent: "will-will-will-will-will's-will-to-will"
14
+ },
15
+ { # German
16
+ text: "Acht alte Ameisen aßen am Abend Ananas.",
17
+ lower: "acht alte ameisen aßen am abend ananas.",
18
+ upper: "ACHT ALTE AMEISEN AẞEN AM ABEND ANANAS.",
19
+ permanent: "acht-alte-ameisen-assen-am-abend-ananas",
20
+ },
21
+ { # German
22
+ text: "Hämmer Hämmer? Hämmer hämmer.",
23
+ lower: "hämmer hämmer? hämmer hämmer.",
24
+ upper: "HÄMMER HÄMMER? HÄMMER HÄMMER.",
25
+ permanent: "haemmer-haemmer-haemmer-haemmer",
26
+ },
27
+ { # German
28
+ text: "Fünf Ferkel fressen frisches Futter.",
29
+ lower: "fünf ferkel fressen frisches futter.",
30
+ upper: "FÜNF FERKEL FRESSEN FRISCHES FUTTER.",
31
+ permanent: "fuenf-ferkel-fressen-frisches-futter",
32
+ },
33
+ {
34
+ text: "Ödögidöggi",
35
+ lower: "ödögidöggi",
36
+ upper: "ÖDÖGIDÖGGI",
37
+ permanent: "oedoegidoeggi",
38
+ },
39
+ { # Polish
40
+ text: "Ćma ćmę ćmi.",
41
+ lower: "ćma ćmę ćmi.",
42
+ upper: "ĆMA ĆMĘ ĆMI.",
43
+ permanent: "cma-cme-cmi",
44
+ },
45
+ { # Polish
46
+ text: "Żubr żuł żuchwą żurawinę.",
47
+ lower: "żubr żuł żuchwą żurawinę.",
48
+ upper: "ŻUBR ŻUŁ ŻUCHWĄ ŻURAWINĘ.",
49
+ permanent: "zubr-zul-zuchwa-zurawine",
50
+ },
51
+ { # Polish
52
+ text: "Pchnąć w tę łódź jeża lub ośm skrzyń fig.",
53
+ lower: "pchnąć w tę łódź jeża lub ośm skrzyń fig.",
54
+ upper: "PCHNĄĆ W TĘ ŁÓDŹ JEŻA LUB OŚM SKRZYŃ FIG.",
55
+ permanent: "pchnac-w-te-lodz-jeza-lub-osm-skrzyn-fig",
56
+ },
57
+ { # Czech
58
+ text: "Čistý s Čistou čistili činčilový čepec.",
59
+ lower: "čistý s čistou čistili činčilový čepec.",
60
+ upper: "ČISTÝ S ČISTOU ČISTILI ČINČILOVÝ ČEPEC.",
61
+ permanent: "cisty-s-cistou-cistili-cincilovy-cepec",
62
+ },
63
+ { # Czech
64
+ text: "Řekni řeřicha.",
65
+ lower: "řekni řeřicha.",
66
+ upper: "ŘEKNI ŘEŘICHA.",
67
+ permanent: "rekni-rericha",
68
+ },
69
+ { # Polish
70
+ text: "Zażółć gęślą jaźń",
71
+ lower: "zażółć gęślą jaźń",
72
+ upper: "ZAŻÓŁĆ GĘŚLĄ JAŹŃ",
73
+ permanent: "zazolc-gesla-jazn",
74
+ },
75
+ {
76
+ text: "À l’époque de la conquête de la Gaule par les armées",
77
+ lower: "à l’époque de la conquête de la gaule par les armées",
78
+ upper: "À L’ÉPOQUE DE LA CONQUÊTE DE LA GAULE PAR LES ARMÉES",
79
+ permanent: "a-l’epoque-de-la-conquete-de-la-gaule-par-les-armees",
80
+ },
81
+ {
82
+ text: "Zalyžařivší si lyžař potkal nezalyžařivšího si lyžaře.",
83
+ lower: "zalyžařivší si lyžař potkal nezalyžařivšího si lyžaře.",
84
+ upper: "ZALYŽAŘIVŠÍ SI LYŽAŘ POTKAL NEZALYŽAŘIVŠÍHO SI LYŽAŘE.",
85
+ permanent: "zalyzarivsi-si-lyzar-potkal-nezalyzarivsiho-si-lyzare",
86
+ },
87
+ {
88
+ text: "Náš pan kaplan v kapli plakal.",
89
+ lower: "náš pan kaplan v kapli plakal.",
90
+ upper: "NÁŠ PAN KAPLAN V KAPLI PLAKAL.",
91
+ permanent: "nas-pan-kaplan-v-kapli-plakal",
92
+ },
93
+ {
94
+ text: "¿Quién lo desenladrillará?",
95
+ lower: "¿quién lo desenladrillará?",
96
+ upper: "¿QUIÉN LO DESENLADRILLARÁ?",
97
+ permanent: "quien-lo-desenladrillara",
98
+ },
99
+ {
100
+ text: "clavó un clavito Pablito.",
101
+ lower: "clavó un clavito pablito.",
102
+ upper: "CLAVÓ UN CLAVITO PABLITO.",
103
+ permanent: "clavo-un-clavito-pablito",
104
+ },
105
+ {
106
+ text: "In Perù però perì.",
107
+ lower: "in perù però perì.",
108
+ upper: "IN PERÙ PERÒ PERÌ.",
109
+ permanent: "in-peru-pero-peri",
110
+ },
111
+ {
112
+ text: "Ĉu ŝi ĉiam ĉe ĉio ruĝiĝas?",
113
+ lower: "ĉu ŝi ĉiam ĉe ĉio ruĝiĝas?",
114
+ upper: "ĈU ŜI ĈIAM ĈE ĈIO RUĜIĜAS?",
115
+ permanent: "cu-si-ciam-ce-cio-rugigas",
116
+ },
117
+ {
118
+ text: "Eĥoŝanĝo ĉiu-ĵaŭde.",
119
+ lower: "eĥoŝanĝo ĉiu-ĵaŭde.",
120
+ upper: "EĤOŜANĜO ĈIU-ĴAŬDE.",
121
+ permanent: "ehosango-ciu-jaude",
122
+ },
123
+ {
124
+ text: "Árni á Á á á á beit (við á).",
125
+ lower: "árni á á á á á beit (við á).",
126
+ upper: "ÁRNI Á Á Á Á Á BEIT (VIÐ Á).",
127
+ permanent: "arni-a-a-a-a-a-beit-(vid-a)",
128
+ },
129
+ {
130
+ text: "Það fer að verða verra ferðaveðrið",
131
+ lower: "það fer að verða verra ferðaveðrið",
132
+ upper: "ÞAÐ FER AÐ VERÐA VERRA FERÐAVEÐRIÐ",
133
+ permanent: "pad-fer-ad-verda-verra-ferdavedrid",
134
+ },
135
+ {
136
+ text: "Четыре чёрненьких чумазеньких чертёнка",
137
+ lower: "четыре чёрненьких чумазеньких чертёнка",
138
+ upper: "ЧЕТЫРЕ ЧЁРНЕНЬКИХ ЧУМАЗЕНЬКИХ ЧЕРТЁНКА",
139
+ permanent: "четыре-чёрненьких-чумазеньких-чертёнка",
140
+ },
141
+ {
142
+ text: "чертили чёрными чернилами чертёж.",
143
+ lower: "чертили чёрными чернилами чертёж.",
144
+ upper: "ЧЕРТИЛИ ЧЁРНЫМИ ЧЕРНИЛАМИ ЧЕРТЁЖ.",
145
+ permanent: "чертили-чёрными-чернилами-чертёж",
146
+ },
147
+ {
148
+ text: "Чайные чашки в печали, скучая, бренча закричали.",
149
+ lower: "чайные чашки в печали, скучая, бренча закричали.",
150
+ upper: "ЧАЙНЫЕ ЧАШКИ В ПЕЧАЛИ, СКУЧАЯ, БРЕНЧА ЗАКРИЧАЛИ.",
151
+ permanent: "чайные-чашки-в-печали-скучая-бренча-закричали",
152
+ },
153
+ {
154
+ text: "Недопереквалифицировавшийся.",
155
+ lower: "недопереквалифицировавшийся.",
156
+ upper: "НЕДОПЕРЕКВАЛИФИЦИРОВАВШИЙСЯ.",
157
+ permanent: "недопереквалифицировавшийся",
158
+ },
159
+ {
160
+ text: "Как в капюшоне он смешон",
161
+ lower: "как в капюшоне он смешон",
162
+ upper: "КАК В КАПЮШОНЕ ОН СМЕШОН",
163
+ permanent: "как-в-капюшоне-он-смешон",
164
+ },
165
+ {
166
+ text: "Стоит гора посреди двора.",
167
+ lower: "стоит гора посреди двора.",
168
+ upper: "СТОИТ ГОРА ПОСРЕДИ ДВОРА.",
169
+ permanent: "стоит-гора-посреди-двора",
170
+ },
171
+ {
172
+ text: "Μια τίγρη με τρία τιγράκια.",
173
+ lower: "μια τίγρη με τρία τιγράκια.",
174
+ upper: "ΜΙΑ ΤΊΓΡΗ ΜΕ ΤΡΊΑ ΤΙΓΡΆΚΙΑ.",
175
+ permanent: "mia-tigre-me-tria-tigrakia",
176
+ },
177
+ {
178
+ text: "Το ξίδι του Ξέρξη ξίδιασε",
179
+ lower: "το ξίδι του ξέρξη ξίδιασε",
180
+ upper: "ΤΟ ΞΊΔΙ ΤΟΥ ΞΈΡΞΗ ΞΊΔΙΑΣΕ",
181
+ permanent: "to-xidi-toy-xerxe-xidiase",
182
+ },
183
+ {
184
+ text: "Πίτα σπανακόπιτα σπανακολαδοφραγκοσυκοπαντζαροκολοκυθόπιτα.",
185
+ lower: "πίτα σπανακόπιτα σπανακολαδοφραγκοσυκοπαντζαροκολοκυθόπιτα.",
186
+ upper: "ΠΊΤΑ ΣΠΑΝΑΚΌΠΙΤΑ ΣΠΑΝΑΚΟΛΑΔΟΦΡΑΓΚΟΣΥΚΟΠΑΝΤΖΑΡΟΚΟΛΟΚΥΘΌΠΙΤΑ.",
187
+ permanent:
188
+ "pita-spanakopita-spanakoladophragkosykopantzarokolokythopita",
189
+ },
190
+ {
191
+ text: "Κοράλι ψιλοκόραλο και ψιλοκοραλάκι.",
192
+ lower: "κοράλι ψιλοκόραλο και ψιλοκοραλάκι.",
193
+ upper: "ΚΟΡΆΛΙ ΨΙΛΟΚΌΡΑΛΟ ΚΑΙ ΨΙΛΟΚΟΡΑΛΆΚΙ.",
194
+ permanent: "korali-psilokoralo-kai-psilokoralaki",
195
+ },
196
+ {
197
+ text: "É muito socó para um socó só coçar.",
198
+ lower: "é muito socó para um socó só coçar.",
199
+ upper: "É MUITO SOCÓ PARA UM SOCÓ SÓ COÇAR.",
200
+ permanent: "e-muito-soco-para-um-soco-so-cocar",
201
+ },
202
+ {
203
+ text: "Mon père est maire, mon frère est masseur.",
204
+ lower: "mon père est maire, mon frère est masseur.",
205
+ upper: "MON PÈRE EST MAIRE, MON FRÈRE EST MASSEUR.",
206
+ permanent: "mon-pere-est-maire-mon-frere-est-masseur",
207
+ },
208
+ {
209
+ text: "Se não percebeste,",
210
+ lower: "se não percebeste,",
211
+ upper: "SE NÃO PERCEBESTE,",
212
+ permanent: "se-nao-percebeste",
213
+ },
214
+ {
215
+ text: "rôt tenta chat",
216
+ lower: "rôt tenta chat",
217
+ upper: "RÔT TENTA CHAT",
218
+ permanent: "rot-tenta-chat",
219
+ },
220
+ {
221
+ text: "Nyelvtörők",
222
+ lower: "nyelvtörők",
223
+ upper: "NYELVTÖRŐK",
224
+ permanent: "nyelvtoeroek",
225
+ },
226
+ {
227
+ text: "Ein hælv kælv låg i elva og flaut på ein sælapinne.",
228
+ lower: "ein hælv kælv låg i elva og flaut på ein sælapinne.",
229
+ upper: "EIN HÆLV KÆLV LÅG I ELVA OG FLAUT PÅ EIN SÆLAPINNE.",
230
+ permanent: "ein-haelv-kaelv-lag-i-elva-og-flaut-pa-ein-saelapinne",
231
+ },
232
+ # {
233
+ # text: "",
234
+ # lower: "",
235
+ # upper: "",
236
+ # permanent: "",
237
+ # },
238
+ ].each do |item|
239
+ text, lower, upper, permanent = item.values
240
+
241
+ it "change '#{text}' to lowercase" do
242
+ subject.downcase(text).should eq(lower)
243
+ end
244
+
245
+ it "change '#{text}' to uppercase" do
246
+ subject.upcase(text).should eq(upper)
247
+ end
248
+
249
+ it "change '#{text}' to permanent" do
250
+ subject.permanent(text).should eq(permanent)
251
+ end
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Diacritics::String do
5
+ class String
6
+ include Diacritics::String
7
+ end
8
+
9
+ context "#diacritics_downcase" do
10
+ it "downcase String with diacritics" do
11
+ string = "ŁoreM Ìpsum Ðolór. Šit Ämet"
12
+ result = "łorem ìpsum ðolór. šit ämet"
13
+
14
+ string.diacritics_downcase.should eq(result)
15
+ end
16
+ end
17
+
18
+ context "#diacritics_upcase" do
19
+ it "upcase String with diacritics" do
20
+ string = "łorem ìpsum ðolÓr. šit ämet"
21
+ result = "ŁOREM ÌPSUM ÐOLÓR. ŠIT ÄMET"
22
+
23
+ string.diacritics_upcase.should eq(result)
24
+ end
25
+ end
26
+
27
+ context "#permanent_link" do
28
+ it "permanent String with diacritics" do
29
+ string = "Łorem ìpsum ÐolÓr. Šit ämet"
30
+ result = "lorem-ipsum-dolor-sit-aemet"
31
+
32
+ string.permanent_link.should eq(result)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ require 'diacritics'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diacritics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksander Malaszkiewicz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-16 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - alek@fractalsoft.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .ruby-gemset
51
+ - .ruby-version
52
+ - .travis.yml
53
+ - CHANGELOG.md
54
+ - Gemfile
55
+ - Guardfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - diacritics.gemspec
60
+ - lib/diacritics.rb
61
+ - lib/diacritics/alphabet.rb
62
+ - lib/diacritics/cases.rb
63
+ - lib/diacritics/string.rb
64
+ - lib/diacritics/version.rb
65
+ - spec/diacritics/alphabet_spec.rb
66
+ - spec/diacritics/cases_spec.rb
67
+ - spec/diacritics/string_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: ''
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Support diacritics
93
+ test_files:
94
+ - spec/diacritics/alphabet_spec.rb
95
+ - spec/diacritics/cases_spec.rb
96
+ - spec/diacritics/string_spec.rb
97
+ - spec/spec_helper.rb