babosa 1.0.4 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +12 -0
- data/README.md +80 -117
- data/Rakefile +9 -8
- data/lib/babosa.rb +2 -4
- data/lib/babosa/identifier.rb +82 -121
- data/lib/babosa/transliterator/base.rb +57 -56
- data/lib/babosa/transliterator/bulgarian.rb +3 -2
- data/lib/babosa/transliterator/cyrillic.rb +5 -5
- data/lib/babosa/transliterator/danish.rb +3 -3
- data/lib/babosa/transliterator/german.rb +3 -2
- data/lib/babosa/transliterator/greek.rb +4 -3
- data/lib/babosa/transliterator/hindi.rb +3 -2
- data/lib/babosa/transliterator/latin.rb +5 -5
- data/lib/babosa/transliterator/macedonian.rb +3 -2
- data/lib/babosa/transliterator/norwegian.rb +3 -3
- data/lib/babosa/transliterator/romanian.rb +3 -2
- data/lib/babosa/transliterator/russian.rb +3 -2
- data/lib/babosa/transliterator/serbian.rb +29 -27
- data/lib/babosa/transliterator/spanish.rb +2 -2
- data/lib/babosa/transliterator/swedish.rb +3 -3
- data/lib/babosa/transliterator/turkish.rb +8 -8
- data/lib/babosa/transliterator/ukrainian.rb +5 -4
- data/lib/babosa/transliterator/vietnamese.rb +4 -3
- data/lib/babosa/version.rb +3 -1
- data/spec/{babosa_spec.rb → identifier_spec.rb} +9 -10
- data/spec/spec_helper.rb +6 -6
- data/spec/transliterators/base_spec.rb +5 -6
- data/spec/transliterators/bulgarian_spec.rb +4 -5
- data/spec/transliterators/danish_spec.rb +5 -6
- data/spec/transliterators/german_spec.rb +4 -5
- data/spec/transliterators/greek_spec.rb +7 -7
- data/spec/transliterators/hindi_spec.rb +7 -7
- data/spec/transliterators/latin_spec.rb +3 -4
- data/spec/transliterators/macedonian_spec.rb +3 -4
- data/spec/transliterators/norwegian_spec.rb +4 -4
- data/spec/transliterators/polish_spec.rb +3 -5
- data/spec/transliterators/romanian_spec.rb +5 -6
- data/spec/transliterators/russian_spec.rb +3 -4
- data/spec/transliterators/serbian_spec.rb +6 -7
- data/spec/transliterators/spanish_spec.rb +4 -5
- data/spec/transliterators/swedish_spec.rb +7 -7
- data/spec/transliterators/turkish_spec.rb +24 -24
- data/spec/transliterators/ukrainian_spec.rb +74 -75
- data/spec/transliterators/vietnamese_spec.rb +10 -10
- metadata +17 -38
- data/lib/babosa/utf8/active_support_proxy.rb +0 -38
- data/lib/babosa/utf8/dumb_proxy.rb +0 -49
- data/lib/babosa/utf8/java_proxy.rb +0 -22
- data/lib/babosa/utf8/mappings.rb +0 -193
- data/lib/babosa/utf8/proxy.rb +0 -125
- data/lib/babosa/utf8/unicode_proxy.rb +0 -23
- data/spec/utf8_proxy_spec.rb +0 -52
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
module Babosa
|
4
|
-
module Transliterator
|
5
|
-
class Turkish < Latin
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Babosa
|
4
|
+
module Transliterator
|
5
|
+
class Turkish < Latin
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Babosa
|
3
4
|
module Transliterator
|
4
5
|
class Ukrainian < Cyrillic
|
@@ -18,13 +19,13 @@ module Babosa
|
|
18
19
|
"Х" => "Kh",
|
19
20
|
"х" => "kh",
|
20
21
|
"Ц" => "Ts",
|
21
|
-
"ц" =>
|
22
|
+
"ц" => "ts",
|
22
23
|
"Щ" => "Shch",
|
23
24
|
"щ" => "shch",
|
24
25
|
"ю" => "iu",
|
25
26
|
"я" => "ia",
|
26
27
|
"'" => ""
|
27
|
-
}
|
28
|
+
}.freeze
|
28
29
|
end
|
29
30
|
end
|
30
|
-
end
|
31
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Babosa
|
3
4
|
module Transliterator
|
4
5
|
class Vietnamese < Latin
|
@@ -137,7 +138,7 @@ module Babosa
|
|
137
138
|
"Ỹ" => "Y",
|
138
139
|
"đ" => "d",
|
139
140
|
"Đ" => "D"
|
140
|
-
}
|
141
|
+
}.freeze
|
141
142
|
end
|
142
143
|
end
|
143
|
-
end
|
144
|
+
end
|
data/lib/babosa/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Identifier do
|
6
6
|
it "should respond_to :empty?" do
|
7
7
|
expect("".to_slug).to respond_to(:empty?)
|
8
8
|
end
|
@@ -10,7 +10,7 @@ describe Babosa::Identifier do
|
|
10
10
|
%w[approximate_ascii clean downcase word_chars normalize to_ascii upcase with_dashes].each do |method|
|
11
11
|
describe "##{method}" do
|
12
12
|
it "should work with invalid UTF-8 strings" do
|
13
|
-
expect {"\x93abc".to_slug.send method}.not_to raise_exception
|
13
|
+
expect { "\x93abc".to_slug.send method }.not_to raise_exception
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -54,9 +54,8 @@ describe Babosa::Identifier do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "#normalize" do
|
57
|
-
|
58
57
|
it "should allow passing locale as key for :transliterate" do
|
59
|
-
expect("ö".to_slug.clean.normalize(:
|
58
|
+
expect("ö".to_slug.clean.normalize(transliterate: :german)).to eql("oe")
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should replace whitespace with dashes" do
|
@@ -102,7 +101,7 @@ describe Babosa::Identifier do
|
|
102
101
|
context "with to_ascii option" do
|
103
102
|
it "should approximate and strip non ascii" do
|
104
103
|
ss = "カタカナ: katakana is über cool".to_slug
|
105
|
-
expect(ss.normalize(:
|
104
|
+
expect(ss.normalize(to_ascii: true)).to eql("katakana-is-uber-cool")
|
106
105
|
end
|
107
106
|
end
|
108
107
|
end
|
@@ -139,16 +138,16 @@ describe Babosa::Identifier do
|
|
139
138
|
expect("¿¿¿hello... world???".to_slug.to_ruby_method).to eql("hello_world?")
|
140
139
|
expect("カタカナ: katakana is über cool".to_slug.to_ruby_method).to eql("katakana_is_uber_cool")
|
141
140
|
expect("カタカナ: katakana is über cool!".to_slug.to_ruby_method).to eql("katakana_is_uber_cool!")
|
142
|
-
expect("カタカナ: katakana is über cool".to_slug.to_ruby_method(false)).to eql("katakana_is_uber_cool")
|
141
|
+
expect("カタカナ: katakana is über cool".to_slug.to_ruby_method(allow_bangs: false)).to eql("katakana_is_uber_cool")
|
143
142
|
end
|
144
143
|
|
145
144
|
it "should optionally remove trailing punctuation" do
|
146
|
-
expect("¿¿¿hello... world???".to_slug.to_ruby_method(false)).to eql("hello_world")
|
145
|
+
expect("¿¿¿hello... world???".to_slug.to_ruby_method(allow_bangs: false)).to eql("hello_world")
|
147
146
|
end
|
148
147
|
|
149
148
|
it "should raise an error when it would generate an impossible method name" do
|
150
149
|
# "1".to_identifier.to_ruby_method
|
151
|
-
expect {"1".to_identifier.to_ruby_method}.to raise_error(Babosa::Identifier::Error)
|
150
|
+
expect { "1".to_identifier.to_ruby_method }.to raise_error(Babosa::Identifier::Error)
|
152
151
|
end
|
153
152
|
|
154
153
|
it "should raise Babosa::Error error when the string is nil" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if ENV[
|
4
|
-
require
|
3
|
+
if ENV["COV"]
|
4
|
+
require "simplecov"
|
5
5
|
SimpleCov.start
|
6
6
|
end
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "bundler/setup"
|
9
|
+
require "babosa"
|
10
10
|
|
11
11
|
shared_examples_for "a latin transliterator" do
|
12
12
|
let(:t) { described_class.instance }
|
@@ -42,4 +42,4 @@ shared_examples_for "a hindi transliterator" do
|
|
42
42
|
string = "आदित्य तापड़िया"
|
43
43
|
expect(t.transliterate(string)).to match(/[\x0-\x7f]/)
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
6
|
-
|
5
|
+
describe Babosa::Transliterator::Base do
|
6
|
+
let(:t) { Babosa::Transliterator::Base.instance }
|
7
7
|
|
8
8
|
it "should transliterate 'smart' quotes" do
|
9
9
|
expect(t.transliterate("’")).to eql("'")
|
@@ -12,5 +12,4 @@ describe Babosa::Transliterator::Base do
|
|
12
12
|
it "should transliterate non-breaking spaces" do
|
13
13
|
expect(t.transliterate("\xc2\xa0")).to eql(" ")
|
14
14
|
end
|
15
|
-
|
16
|
-
end
|
15
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Bulgarian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a cyrillic transliterator"
|
8
8
|
|
@@ -14,7 +14,6 @@ describe Babosa::Transliterator::Bulgarian do
|
|
14
14
|
"Щъркел" => "Shturkel",
|
15
15
|
"полицай" => "policai"
|
16
16
|
}
|
17
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
17
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
18
18
|
end
|
19
|
-
|
20
19
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Danish do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
@@ -11,7 +11,6 @@ describe Babosa::Transliterator::Danish do
|
|
11
11
|
"Ærøskøbing" => "Aeroeskoebing",
|
12
12
|
"Årslev" => "Aarslev"
|
13
13
|
}
|
14
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
14
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
15
15
|
end
|
16
|
-
|
17
|
-
end
|
16
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::German do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
@@ -13,5 +13,4 @@ describe Babosa::Transliterator::German do
|
|
13
13
|
it "should transliterate vowels with umlauts" do
|
14
14
|
expect(t.transliterate("üöä")).to eql("ueoeae")
|
15
15
|
end
|
16
|
-
|
17
|
-
end
|
16
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Greek do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a greek transliterator"
|
8
8
|
|
9
9
|
it "should transliterate various characters" do
|
10
10
|
examples = {
|
11
|
-
"Γερμανία"
|
12
|
-
"Αυστρία"
|
13
|
-
"Ιταλία"
|
11
|
+
"Γερμανία" => "Germania",
|
12
|
+
"Αυστρία" => "Aystria",
|
13
|
+
"Ιταλία" => "Italia"
|
14
14
|
}
|
15
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
15
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
16
16
|
end
|
17
17
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Hindi do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a hindi transliterator"
|
8
8
|
|
9
9
|
it "should transliterate hindi characters" do
|
10
10
|
examples = {
|
11
|
-
"आदित्य"
|
12
|
-
"सबरीमाला करवाना पायसम"
|
13
|
-
"सक्रांति आँख"
|
11
|
+
"आदित्य" => "aadity",
|
12
|
+
"सबरीमाला करवाना पायसम" => "sbriimaalaa krvaanaa paaysm",
|
13
|
+
"सक्रांति आँख" => "skraanti aankh"
|
14
14
|
}
|
15
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
15
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
16
16
|
end
|
17
17
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Latin do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
|
-
|
9
8
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Macedonian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a cyrillic transliterator"
|
8
|
-
|
9
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Norwegian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
@@ -13,6 +13,6 @@ describe Babosa::Transliterator::Norwegian do
|
|
13
13
|
"Åre" => "Aare",
|
14
14
|
"Håkon" => "Haakon"
|
15
15
|
}
|
16
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
16
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
17
17
|
end
|
18
18
|
end
|
@@ -1,14 +1,12 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Romanian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
9
9
|
it "should transliterate various characters" do
|
10
10
|
expect(t.transliterate("ĄąĆćĘꣳŃńÓ󌜏źŻż")).to eql("AaCcEeLlNnOoSsZzZz")
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
14
|
-
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Romanian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
@@ -13,7 +13,6 @@ describe Babosa::Transliterator::Romanian do
|
|
13
13
|
"Țară" => "Tara",
|
14
14
|
"Șanț" => "Sant"
|
15
15
|
}
|
16
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
16
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
17
17
|
end
|
18
|
-
|
19
|
-
end
|
18
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Russian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a cyrillic transliterator"
|
8
|
-
|
9
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Serbian do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
it_behaves_like "a cyrillic transliterator"
|
@@ -17,9 +17,8 @@ describe Babosa::Transliterator::Serbian do
|
|
17
17
|
"škola" => "shkola",
|
18
18
|
"Ђорђе" => "Djordje",
|
19
19
|
"Инђија" => "Indjija",
|
20
|
-
"Школа" => "Shkola"
|
20
|
+
"Школа" => "Shkola"
|
21
21
|
}
|
22
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
22
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
23
23
|
end
|
24
|
-
|
25
|
-
end
|
24
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Spanish do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
9
9
|
it "should transliterate ñ" do
|
10
10
|
expect(t.transliterate("ñ")).to eql("ni")
|
11
11
|
end
|
12
|
-
|
13
|
-
end
|
12
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
require "spec_helper"
|
5
4
|
|
5
|
+
describe Babosa::Transliterator::Swedish do
|
6
6
|
let(:t) { described_class.instance }
|
7
7
|
it_behaves_like "a latin transliterator"
|
8
8
|
|
9
9
|
it "should transliterate various characters" do
|
10
10
|
examples = {
|
11
11
|
"Räksmörgås" => "Raeksmoergaas",
|
12
|
-
"Öre"
|
13
|
-
"Åre"
|
14
|
-
"Älskar"
|
12
|
+
"Öre" => "Oere",
|
13
|
+
"Åre" => "Aare",
|
14
|
+
"Älskar" => "Aelskar"
|
15
15
|
}
|
16
|
-
examples.each {|k, v| expect(t.transliterate(k)).to eql(v)}
|
16
|
+
examples.each { |k, v| expect(t.transliterate(k)).to eql(v) }
|
17
17
|
end
|
18
18
|
end
|