babosa 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.md +19 -0
- data/README.md +1 -19
- data/lib/babosa/candidates.rb +45 -0
- data/lib/babosa/generator.rb +24 -0
- data/lib/babosa/transliterator/base.rb +1 -0
- data/lib/babosa/transliterator/macedonian.rb +3 -1
- data/lib/babosa/transliterator/vietnamese.rb +143 -0
- data/lib/babosa/version.rb +1 -1
- data/spec/transliterators/vietnamese_spec.rb +18 -0
- metadata +35 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ee04fad8c458a32dea08b5f6483d817d359dab4
|
4
|
+
data.tar.gz: 22385c9ae0e279fc6531a6ad6e9851ec3d4f4e81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad5f5a7e2bbfd63ab2e0a89878b54dc52a96f6929f68dbb94070d86e7b0515d7f3fb0e6e30d4e3152320a07fe7684833f23135569e7200e4aad0f9930bb3b261
|
7
|
+
data.tar.gz: 95e010b9b9c5138af14454258f332a0e32e735354ad49a65ed4f22514110e159909e4a4e714a06443a02f4d9f64edfe00ac2cf48f10036488beb2f4a4abde977
|
data/Changelog.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Babosa Changelog
|
2
|
+
|
3
|
+
* 0.3.11 - Added support for Vietnamese
|
4
|
+
* 0.3.10 - Fixed Macedonian "S/S". Don't `include JRuby` unnecessarily.
|
5
|
+
* 0.3.9 - Added missing Greek vowels with diaeresis.
|
6
|
+
* 0.3.8 - Correct and improve Macedonian support.
|
7
|
+
* 0.3.7 - Fix compatibility with Ruby 1.8.7. Add Swedish support.
|
8
|
+
* 0.3.6 - Allow multiple transliterators. Add Greek support.
|
9
|
+
* 0.3.5 - Don't strip underscores from identifiers.
|
10
|
+
* 0.3.4 - Add Romanian support.
|
11
|
+
* 0.3.3 - Add Norwegian support.
|
12
|
+
* 0.3.2 - Improve Macedonian support.
|
13
|
+
* 0.3.1 - Small fixes to Cyrillic.
|
14
|
+
* 0.3.0 - Cyrillic support. Improve support for various Unicode spaces and dashes.
|
15
|
+
* 0.2.2 - Fix for "smart" quote handling.
|
16
|
+
* 0.2.1 - Implement #empty? for compatiblity with Active Support's #blank?.
|
17
|
+
* 0.2.0 - Added support for Danish. Added method to generate Ruby identifiers. Improved performance.
|
18
|
+
* 0.1.1 - Added support for Serbian.
|
19
|
+
* 0.1.0 - Initial extraction from FriendlyId.
|
data/README.md
CHANGED
@@ -239,6 +239,7 @@ tracker](http://github.com/norman/babosa/issues).
|
|
239
239
|
|
240
240
|
Many thanks to the following people for their help:
|
241
241
|
|
242
|
+
* [anhkind](https://github.com/anhkind) - Vietnamese support
|
242
243
|
* [Martins Zakis](https://github.com/martins) - Bug fixes
|
243
244
|
* [Vassilis Rodokanakis](https://github.com/vrodokanakis) - Greek support
|
244
245
|
* [Peco Danajlovski](https://github.com/Vortex) - Macedonian support
|
@@ -255,25 +256,6 @@ Many thanks to the following people for their help:
|
|
255
256
|
* [Milan Dobrota](https://github.com/milandobrota) - Serbian support
|
256
257
|
|
257
258
|
|
258
|
-
## Changelog
|
259
|
-
|
260
|
-
* 0.3.10 - Fixed Macedonian "S/S". Don't `include JRuby` unnecessarily.
|
261
|
-
* 0.3.9 - Added missing Greek vowels with diaeresis.
|
262
|
-
* 0.3.8 - Correct and improve Macedonian support.
|
263
|
-
* 0.3.7 - Fix compatibility with Ruby 1.8.7. Add Swedish support.
|
264
|
-
* 0.3.6 - Allow multiple transliterators. Add Greek support.
|
265
|
-
* 0.3.5 - Don't strip underscores from identifiers.
|
266
|
-
* 0.3.4 - Add Romanian support.
|
267
|
-
* 0.3.3 - Add Norwegian support.
|
268
|
-
* 0.3.2 - Improve Macedonian support.
|
269
|
-
* 0.3.1 - Small fixes to Cyrillic.
|
270
|
-
* 0.3.0 - Cyrillic support. Improve support for various Unicode spaces and dashes.
|
271
|
-
* 0.2.2 - Fix for "smart" quote handling.
|
272
|
-
* 0.2.1 - Implement #empty? for compatiblity with Active Support's #blank?.
|
273
|
-
* 0.2.0 - Added support for Danish. Added method to generate Ruby identifiers. Improved performance.
|
274
|
-
* 0.1.1 - Added support for Serbian.
|
275
|
-
* 0.1.0 - Initial extraction from FriendlyId.
|
276
|
-
|
277
259
|
## Copyright
|
278
260
|
|
279
261
|
Copyright (c) 2010-2013 Norman Clarke
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Babosa
|
4
|
+
|
5
|
+
# This iterates through slug candidates and generates them lazily. In other
|
6
|
+
# words, if the first candidate succeeds, the remaning ones are not
|
7
|
+
# evaluated. It also appends a fallback candidate which uses the final
|
8
|
+
# candidate's slug plus a GUID.
|
9
|
+
class Candidates
|
10
|
+
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
def initialize(object, *array)
|
14
|
+
@candidates = to_candidate_array(object, array.flatten(1))
|
15
|
+
@candidates << (@candidates.last.dup << -> {SecureRandom.uuid})
|
16
|
+
end
|
17
|
+
|
18
|
+
def each(*args, &block)
|
19
|
+
@candidates.each(*args) do |candidate|
|
20
|
+
yield candidate.map(&:call).join(' ').to_slug.normalize!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def to_candidate_array(object, array)
|
27
|
+
array.map do |candidate|
|
28
|
+
case candidate
|
29
|
+
when String
|
30
|
+
[->{candidate}]
|
31
|
+
when Array
|
32
|
+
to_candidate_array(object, candidate).flatten
|
33
|
+
when Symbol
|
34
|
+
[object.method(candidate)]
|
35
|
+
else
|
36
|
+
if candidate.respond_to?(:call)
|
37
|
+
[candidate]
|
38
|
+
else
|
39
|
+
[->{candidate.to_s}]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Babosa
|
4
|
+
# A simple slug generator using a Set as a backend. Obviously this is silly
|
5
|
+
# and potentially a great way to leak memory, but it demonstrates the
|
6
|
+
# funcionality.
|
7
|
+
class Generator
|
8
|
+
def initialize
|
9
|
+
@set = Set.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def available?(slug)
|
13
|
+
!@set.member?(slug)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(slug)
|
17
|
+
@set.add slug; slug
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate(candidates)
|
21
|
+
candidates.each {|c| return add c if available?(c)}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -20,6 +20,7 @@ module Babosa
|
|
20
20
|
autoload :Swedish, "babosa/transliterator/swedish"
|
21
21
|
autoload :Ukrainian, "babosa/transliterator/ukrainian"
|
22
22
|
autoload :Greek, "babosa/transliterator/greek"
|
23
|
+
autoload :Vietnamese, "babosa/transliterator/vietnamese"
|
23
24
|
|
24
25
|
def self.get(symbol)
|
25
26
|
const_get(symbol.to_s.classify)
|
@@ -12,6 +12,7 @@ module Babosa
|
|
12
12
|
"Ц" => "C",
|
13
13
|
"Ѕ" => "Z",
|
14
14
|
"Ј" => "J",
|
15
|
+
"Х" => "H",
|
15
16
|
"ѓ" => "gj",
|
16
17
|
"љ" => "lj",
|
17
18
|
"њ" => "nj",
|
@@ -20,7 +21,8 @@ module Babosa
|
|
20
21
|
"ж" => "zh",
|
21
22
|
"ц" => "c",
|
22
23
|
"ѕ" => "z",
|
23
|
-
"ј" => "j"
|
24
|
+
"ј" => "j",
|
25
|
+
"х" => "h"
|
24
26
|
}
|
25
27
|
end
|
26
28
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Babosa
|
3
|
+
module Transliterator
|
4
|
+
class Vietnamese < Latin
|
5
|
+
APPROXIMATIONS = {
|
6
|
+
"à" => "a",
|
7
|
+
"á" => "a",
|
8
|
+
"ạ" => "a",
|
9
|
+
"ả" => "a",
|
10
|
+
"ã" => "a",
|
11
|
+
"â" => "a",
|
12
|
+
"ầ" => "a",
|
13
|
+
"ấ" => "a",
|
14
|
+
"ậ" => "a",
|
15
|
+
"ẩ" => "a",
|
16
|
+
"ẫ" => "a",
|
17
|
+
"ă" => "a",
|
18
|
+
"ằ" => "a",
|
19
|
+
"ắ" => "a",
|
20
|
+
"ặ" => "a",
|
21
|
+
"ẳ" => "a",
|
22
|
+
"ẵ" => "a",
|
23
|
+
"À" => "A",
|
24
|
+
"Á" => "A",
|
25
|
+
"Ạ" => "A",
|
26
|
+
"Ả" => "A",
|
27
|
+
"Ã" => "A",
|
28
|
+
"Â" => "A",
|
29
|
+
"Ầ" => "A",
|
30
|
+
"Ấ" => "A",
|
31
|
+
"Ậ" => "A",
|
32
|
+
"Ẩ" => "A",
|
33
|
+
"Ẫ" => "A",
|
34
|
+
"Ă" => "A",
|
35
|
+
"Ằ" => "A",
|
36
|
+
"Ắ" => "A",
|
37
|
+
"Ặ" => "A",
|
38
|
+
"Ẳ" => "A",
|
39
|
+
"Ẵ" => "A",
|
40
|
+
"ì" => "i",
|
41
|
+
"í" => "i",
|
42
|
+
"ị" => "i",
|
43
|
+
"ỉ" => "i",
|
44
|
+
"ĩ" => "i",
|
45
|
+
"Ì" => "I",
|
46
|
+
"Í" => "I",
|
47
|
+
"Ị" => "I",
|
48
|
+
"Ỉ" => "I",
|
49
|
+
"Ĩ" => "I",
|
50
|
+
"ù" => "u",
|
51
|
+
"ú" => "u",
|
52
|
+
"ụ" => "u",
|
53
|
+
"ủ" => "u",
|
54
|
+
"ũ" => "u",
|
55
|
+
"ư" => "u",
|
56
|
+
"ừ" => "u",
|
57
|
+
"ứ" => "u",
|
58
|
+
"ự" => "u",
|
59
|
+
"ử" => "u",
|
60
|
+
"ữ" => "u",
|
61
|
+
"Ù" => "U",
|
62
|
+
"Ú" => "U",
|
63
|
+
"Ụ" => "U",
|
64
|
+
"Ủ" => "U",
|
65
|
+
"Ũ" => "U",
|
66
|
+
"Ư" => "U",
|
67
|
+
"Ừ" => "U",
|
68
|
+
"Ứ" => "U",
|
69
|
+
"Ự" => "U",
|
70
|
+
"Ử" => "U",
|
71
|
+
"Ữ" => "U",
|
72
|
+
"è" => "e",
|
73
|
+
"é" => "e",
|
74
|
+
"ẹ" => "e",
|
75
|
+
"ẻ" => "e",
|
76
|
+
"ẽ" => "e",
|
77
|
+
"ê" => "e",
|
78
|
+
"ề" => "e",
|
79
|
+
"ế" => "e",
|
80
|
+
"ệ" => "e",
|
81
|
+
"ể" => "e",
|
82
|
+
"ễ" => "e",
|
83
|
+
"È" => "E",
|
84
|
+
"É" => "E",
|
85
|
+
"Ẹ" => "E",
|
86
|
+
"Ẻ" => "E",
|
87
|
+
"Ẽ" => "E",
|
88
|
+
"Ê" => "E",
|
89
|
+
"Ề" => "E",
|
90
|
+
"Ế" => "E",
|
91
|
+
"Ệ" => "E",
|
92
|
+
"Ể" => "E",
|
93
|
+
"Ễ" => "E",
|
94
|
+
"ò" => "o",
|
95
|
+
"ó" => "o",
|
96
|
+
"ọ" => "o",
|
97
|
+
"ỏ" => "o",
|
98
|
+
"õ" => "o",
|
99
|
+
"ô" => "o",
|
100
|
+
"ồ" => "o",
|
101
|
+
"ố" => "o",
|
102
|
+
"ộ" => "o",
|
103
|
+
"ổ" => "o",
|
104
|
+
"ỗ" => "o",
|
105
|
+
"ơ" => "o",
|
106
|
+
"ờ" => "o",
|
107
|
+
"ớ" => "o",
|
108
|
+
"ợ" => "o",
|
109
|
+
"ở" => "o",
|
110
|
+
"ỡ" => "o",
|
111
|
+
"Ò" => "O",
|
112
|
+
"Ó" => "O",
|
113
|
+
"Ọ" => "O",
|
114
|
+
"Ỏ" => "O",
|
115
|
+
"Õ" => "O",
|
116
|
+
"Ô" => "O",
|
117
|
+
"Ồ" => "O",
|
118
|
+
"Ố" => "O",
|
119
|
+
"Ộ" => "O",
|
120
|
+
"Ổ" => "O",
|
121
|
+
"Ỗ" => "O",
|
122
|
+
"Ơ" => "O",
|
123
|
+
"Ờ" => "O",
|
124
|
+
"Ớ" => "O",
|
125
|
+
"Ợ" => "O",
|
126
|
+
"Ở" => "O",
|
127
|
+
"Ỡ" => "O",
|
128
|
+
"ỳ" => "y",
|
129
|
+
"ý" => "y",
|
130
|
+
"ỵ" => "y",
|
131
|
+
"ỷ" => "y",
|
132
|
+
"ỹ" => "y",
|
133
|
+
"Ỳ" => "Y",
|
134
|
+
"Ý" => "Y",
|
135
|
+
"Ỵ" => "Y",
|
136
|
+
"Ỷ" => "Y",
|
137
|
+
"Ỹ" => "Y",
|
138
|
+
"đ" => "d",
|
139
|
+
"Đ" => "D"
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/babosa/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe Babosa::Transliterator::Vietnamese do
|
5
|
+
|
6
|
+
let(:t) { described_class.instance }
|
7
|
+
it_behaves_like "a latin transliterator"
|
8
|
+
|
9
|
+
it "should transliterate various characters" do
|
10
|
+
examples = {
|
11
|
+
"làm" => "lam",
|
12
|
+
"đàn ông" => "dan ong",
|
13
|
+
"thật" => "that",
|
14
|
+
"khổ" => "kho"
|
15
|
+
}
|
16
|
+
examples.each {|k, v| t.transliterate(k).should eql(v)}
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,88 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babosa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.3.10
|
4
|
+
version: 0.3.11
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Norman Clarke
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - '>='
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: 2.3.0
|
21
|
-
name: activesupport
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
|
25
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.3.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
32
|
-
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
33
30
|
requirements:
|
34
31
|
- - ~>
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: 2.11.0
|
37
|
-
name: rspec
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
none: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 2.11.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
48
|
-
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
49
44
|
requirements:
|
50
|
-
- -
|
45
|
+
- - '>='
|
51
46
|
- !ruby/object:Gem::Version
|
52
47
|
version: '0'
|
53
|
-
name: simplecov
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
|
-
|
57
|
-
none: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
|
64
|
-
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
65
58
|
requirements:
|
66
|
-
- -
|
59
|
+
- - '>='
|
67
60
|
- !ruby/object:Gem::Version
|
68
61
|
version: '0'
|
69
|
-
name: rake
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
|
-
|
73
|
-
none: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
|
-
description:
|
79
|
-
|
80
|
-
|
69
|
+
description: |2
|
70
|
+
A library for creating slugs. Babosa an extraction and improvement of the
|
71
|
+
string code from FriendlyId, intended to help developers create similar
|
72
|
+
libraries or plugins.
|
81
73
|
email: norman@njclarke.com
|
82
74
|
executables: []
|
83
75
|
extensions: []
|
84
76
|
extra_rdoc_files: []
|
85
77
|
files:
|
78
|
+
- lib/babosa/candidates.rb
|
79
|
+
- lib/babosa/generator.rb
|
86
80
|
- lib/babosa/identifier.rb
|
87
81
|
- lib/babosa/transliterator/base.rb
|
88
82
|
- lib/babosa/transliterator/bulgarian.rb
|
@@ -99,6 +93,7 @@ files:
|
|
99
93
|
- lib/babosa/transliterator/spanish.rb
|
100
94
|
- lib/babosa/transliterator/swedish.rb
|
101
95
|
- lib/babosa/transliterator/ukrainian.rb
|
96
|
+
- lib/babosa/transliterator/vietnamese.rb
|
102
97
|
- lib/babosa/utf8/active_support_proxy.rb
|
103
98
|
- lib/babosa/utf8/dumb_proxy.rb
|
104
99
|
- lib/babosa/utf8/java_proxy.rb
|
@@ -107,6 +102,7 @@ files:
|
|
107
102
|
- lib/babosa/utf8/unicode_proxy.rb
|
108
103
|
- lib/babosa/version.rb
|
109
104
|
- lib/babosa.rb
|
105
|
+
- Changelog.md
|
110
106
|
- README.md
|
111
107
|
- MIT-LICENSE
|
112
108
|
- Rakefile
|
@@ -126,30 +122,30 @@ files:
|
|
126
122
|
- spec/transliterators/spanish_spec.rb
|
127
123
|
- spec/transliterators/swedish_spec.rb
|
128
124
|
- spec/transliterators/ukrainian_spec.rb
|
125
|
+
- spec/transliterators/vietnamese_spec.rb
|
129
126
|
- spec/utf8_proxy_spec.rb
|
130
127
|
- .gemtest
|
131
128
|
homepage: http://norman.github.com/babosa
|
132
129
|
licenses: []
|
130
|
+
metadata: {}
|
133
131
|
post_install_message:
|
134
132
|
rdoc_options: []
|
135
133
|
require_paths:
|
136
134
|
- lib
|
137
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
136
|
requirements:
|
140
|
-
- -
|
137
|
+
- - '>='
|
141
138
|
- !ruby/object:Gem::Version
|
142
139
|
version: '0'
|
143
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
-
none: false
|
145
141
|
requirements:
|
146
|
-
- -
|
142
|
+
- - '>='
|
147
143
|
- !ruby/object:Gem::Version
|
148
144
|
version: '0'
|
149
145
|
requirements: []
|
150
|
-
rubyforge_project:
|
151
|
-
rubygems_version:
|
146
|
+
rubyforge_project: '[none]'
|
147
|
+
rubygems_version: 2.0.3
|
152
148
|
signing_key:
|
153
|
-
specification_version:
|
149
|
+
specification_version: 4
|
154
150
|
summary: A library for creating slugs.
|
155
151
|
test_files: []
|