Permalink
Browse files

Don't use the transliterator gem on 1.8.

Replace the transliteration with Iconv and a regexp.
  • Loading branch information...
1 parent eede04d commit 129bf3b07cec4daadd9b8255eab83cae98e9cefc @Manfred Manfred committed Oct 15, 2012
Showing with 25 additions and 5 deletions.
  1. +2 −1 buckaroo-ideal.gemspec
  2. +18 −4 lib/buckaroo-ideal/util.rb
  3. +5 −0 spec/buckaroo-ideal/util_spec.rb
@@ -16,9 +16,10 @@ Gem::Specification.new do |gem|
gem.version = Buckaroo::Ideal::VERSION
gem.add_dependency 'activesupport'
- gem.add_dependency 'transliterator'
if RUBY_VERSION < "1.9"
gem.add_dependency 'fastercsv'
+ else
+ gem.add_dependency 'transliterator'
end
end
@@ -1,12 +1,26 @@
-require 'transliterator'
-
module Buckaroo
module Ideal
module Util
extend self
- def to_normalized_string(string)
- Transliterator.asciify(string.to_s)
+ if RUBY_VERSION < "1.9"
+
+ require 'iconv'
+
+ STRIP_ACCENTS_RE = /[\^~"`']/
+
+ def to_normalized_string(string)
+ Iconv.iconv('US-ASCII//IGNORE//TRANSLIT', 'UTF-8', string).to_s.gsub(STRIP_ACCENTS_RE, '')
+ end
+
+ else
+
+ require 'transliterator'
+
+ def to_normalized_string(string)
+ Transliterator.asciify(string.to_s)
+ end
+
end
def to_cents(amount)
@@ -7,6 +7,11 @@
result = Buckaroo::Ideal::Util.to_normalized_string('îñtërnâtiônàlizâtiôn')
result.should == 'internationalization'
end
+
+ it 'keeps dashes' do
+ result = Buckaroo::Ideal::Util.to_normalized_string('order-123')
+ result.should == 'order-123'
+ end
end
describe '#to_cents' do

0 comments on commit 129bf3b

Please sign in to comment.