babosa 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -175,6 +175,7 @@ Please use Babosa's [Github issue tracker](http://github.com/norman/babosa/issue
175
175
 
176
176
  ## Changelog
177
177
 
178
+ * 0.3.6 - Allow multiple transliterators. Add Greek support.
178
179
  * 0.3.5 - Don't strip underscores from identifiers.
179
180
  * 0.3.4 - Add Romanian support.
180
181
  * 0.3.3 - Add Norwegian support.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rubygems"
2
2
  require "rake/testtask"
3
3
  require "rake/clean"
4
- require "rake/gempackagetask"
4
+ require "rubygems/package_task"
5
5
 
6
6
  task :default => :spec
7
7
  task :test => :spec
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  gemspec = File.expand_path("../babosa.gemspec", __FILE__)
29
29
  if File.exist? gemspec
30
- Rake::GemPackageTask.new(eval(File.read(gemspec))) { |pkg| }
30
+ Gem::PackageTask.new(eval(File.read(gemspec))) { |pkg| }
31
31
  end
32
32
 
33
33
  require 'rspec/core/rake_task'
@@ -112,9 +112,13 @@ module Babosa
112
112
  # string.transliterate! # => "¡Feliz anio!"
113
113
  # @param *args <Symbol>
114
114
  # @return String
115
- def transliterate!(kind = nil)
116
- transliterator = Transliterator.get(kind || :latin).instance
117
- @wrapped_string = transliterator.transliterate(@wrapped_string)
115
+ def transliterate!(*kinds)
116
+ kinds = [:latin] if kinds.empty?
117
+ kinds.each do |kind|
118
+ transliterator = Transliterator.get(kind).instance
119
+ @wrapped_string = transliterator.transliterate(@wrapped_string)
120
+ end
121
+ @wrapped_string
118
122
  end
119
123
 
120
124
  # Converts dashes to spaces, removes leading and trailing spaces, and
@@ -18,6 +18,7 @@ module Babosa
18
18
  autoload :Serbian, "babosa/transliterator/serbian"
19
19
  autoload :Spanish, "babosa/transliterator/spanish"
20
20
  autoload :Ukrainian, "babosa/transliterator/ukrainian"
21
+ autoload :Greek, "babosa/transliterator/greek"
21
22
 
22
23
  def self.get(symbol)
23
24
  const_get(symbol.to_s.classify)
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ module Babosa
3
+ module Transliterator
4
+ class Greek < Base
5
+ APPROXIMATIONS = {
6
+ "Α" => "A",
7
+ "Ά" => "A",
8
+ "α" => "a",
9
+ "ά" => "a",
10
+ "Β" => "B",
11
+ "β" => "b",
12
+ "Γ" => "G",
13
+ "γ" => "g",
14
+ "Δ" => "D",
15
+ "δ" => "d",
16
+ "Ε" => "E",
17
+ "Έ" => "E",
18
+ "ε" => "e",
19
+ "έ" => "e",
20
+ "Ζ" => "Z",
21
+ "ζ" => "z",
22
+ "Η" => "E",
23
+ "Ή" => "e",
24
+ "η" => "e",
25
+ "ή" => "E",
26
+ "Θ" => "Th",
27
+ "θ" => "th",
28
+ "Ι" => "I",
29
+ "Ί" => "Ι",
30
+ "Î" => "I",
31
+ "ι" => "i",
32
+ "ί" => "i",
33
+ "Κ" => "K",
34
+ "κ" => "k",
35
+ "Λ" => "L",
36
+ "λ" => "l",
37
+ "Μ" => "M",
38
+ "μ" => "m",
39
+ "Ν" => "N",
40
+ "ν" => "n",
41
+ "Ξ" => "X",
42
+ "ξ" => "x",
43
+ "Ο" => "O",
44
+ "Ό" => "O",
45
+ "ο" => "o",
46
+ "ό" => "o",
47
+ "Π" => "P",
48
+ "π" => "p",
49
+ "Ρ" => "R",
50
+ "ρ" => "r",
51
+ "Σ" => "S",
52
+ "σ" => "s",
53
+ "ς" => "s",
54
+ "Τ" => "T",
55
+ "τ" => "t",
56
+ "Υ" => "I",
57
+ "Ύ" => "I",
58
+ "υ" => "i",
59
+ "ύ" => "i",
60
+ "Φ" => "F",
61
+ "φ" => "f",
62
+ "Χ" => "Ch",
63
+ "χ" => "ch",
64
+ "Ψ" => "Ps",
65
+ "ψ" => "ps",
66
+ "Ω" => "O",
67
+ "Ώ" => "O",
68
+ "ω" => "o",
69
+ "ώ" => "o"
70
+ }
71
+ end
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  module Babosa
2
2
  module Version
3
- STRING = "0.3.5"
3
+ STRING = "0.3.6"
4
4
  end
5
5
  end
@@ -34,6 +34,11 @@ describe Babosa::Identifier do
34
34
  string = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS
35
35
  string.to_slug.approximate_ascii.should eql("u")
36
36
  end
37
+
38
+ it "should transliterate using multiple transliterators" do
39
+ string = "свободное režģis"
40
+ string.to_slug.approximate_ascii(:latin, :russian).should eql("svobodnoe rezgis")
41
+ end
37
42
  end
38
43
 
39
44
  describe "#downcase" do
@@ -30,4 +30,13 @@ shared_examples_for "a cyrillic transliterator" do
30
30
  string = "Славься, Отечество наше свободное"
31
31
  t.transliterate(string).should match(/[\x0-\x7f]/)
32
32
  end
33
+ end
34
+
35
+ shared_examples_for "a greek transliterator" do
36
+ let(:t) { described_class.instance }
37
+
38
+ it "should transliterate greek characters" do
39
+ string = "Γερμανία"
40
+ t.transliterate(string).should match(/[\x0-\x7f]/)
41
+ end
33
42
  end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../../spec_helper", __FILE__)
3
+
4
+ describe Babosa::Transliterator::Greek do
5
+
6
+ let(:t) { described_class.instance }
7
+ it_behaves_like "a greek transliterator"
8
+
9
+ it "should transliterate various characters" do
10
+ examples = {
11
+ "Γερμανία" => "Germania",
12
+ "Αυστρία" => "Aistria",
13
+ "Ιταλία" => "Italia"
14
+ }
15
+ examples.each {|k, v| t.transliterate(k).should eql(v)}
16
+ end
17
+ end
metadata CHANGED
@@ -1,66 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: babosa
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.6
4
5
  prerelease:
5
- version: 0.3.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Norman Clarke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-08 00:00:00 -03:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: activesupport
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70212217120220 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 2.3.0
25
22
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70212217120220
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70212217118700 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
35
32
  version: 2.5.0
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: simplecov
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70212217118700
36
+ - !ruby/object:Gem::Dependency
37
+ name: simplecov
38
+ requirement: &70212217117820 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
47
44
  type: :development
48
- version_requirements: *id003
49
- description: " A library for creating slugs. Babosa an extraction and improvement of the\n string code from FriendlyId, intended to help developers create similar\n libraries or plugins.\n"
45
+ prerelease: false
46
+ version_requirements: *70212217117820
47
+ description: ! " A library for creating slugs. Babosa an extraction and improvement
48
+ of the\n string code from FriendlyId, intended to help developers create similar\n
49
+ \ libraries or plugins.\n"
50
50
  email: norman@njclarke.com
51
51
  executables: []
52
-
53
52
  extensions: []
54
-
55
53
  extra_rdoc_files: []
56
-
57
- files:
54
+ files:
58
55
  - lib/babosa/identifier.rb
59
56
  - lib/babosa/transliterator/base.rb
60
57
  - lib/babosa/transliterator/bulgarian.rb
61
58
  - lib/babosa/transliterator/cyrillic.rb
62
59
  - lib/babosa/transliterator/danish.rb
63
60
  - lib/babosa/transliterator/german.rb
61
+ - lib/babosa/transliterator/greek.rb
64
62
  - lib/babosa/transliterator/latin.rb
65
63
  - lib/babosa/transliterator/macedonian.rb
66
64
  - lib/babosa/transliterator/norwegian.rb
@@ -87,6 +85,7 @@ files:
87
85
  - spec/transliterators/bulgarian_spec.rb
88
86
  - spec/transliterators/danish_spec.rb
89
87
  - spec/transliterators/german_spec.rb
88
+ - spec/transliterators/greek_spec.rb
90
89
  - spec/transliterators/macedonian_spec.rb
91
90
  - spec/transliterators/norwegian_spec.rb
92
91
  - spec/transliterators/romanian_spec.rb
@@ -96,33 +95,28 @@ files:
96
95
  - spec/transliterators/ukrainian_spec.rb
97
96
  - spec/utf8_proxy_spec.rb
98
97
  - .gemtest
99
- has_rdoc: true
100
98
  homepage: http://norman.github.com/babosa
101
99
  licenses: []
102
-
103
100
  post_install_message:
104
101
  rdoc_options: []
105
-
106
- require_paths:
102
+ require_paths:
107
103
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
109
105
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
111
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: "0"
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
120
116
  requirements: []
121
-
122
- rubyforge_project: "[none]"
123
- rubygems_version: 1.6.1
117
+ rubyforge_project: ! '[none]'
118
+ rubygems_version: 1.8.10
124
119
  signing_key:
125
120
  specification_version: 3
126
121
  summary: A library for creating slugs.
127
122
  test_files: []
128
-