From 6c4ae0545436e6bc1b9afdfa03e2712e315faed9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 15 Feb 2013 13:36:19 -0800 Subject: [PATCH] Removes iconv dependency Fixes #100 --- lib/text_sentinel.rb | 11 +++-------- spec/components/text_sentinel_spec.rb | 3 +-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb index 61515929ad5..b869a33d968 100644 --- a/lib/text_sentinel.rb +++ b/lib/text_sentinel.rb @@ -1,5 +1,3 @@ -require 'iconv' - # # Given a string, tell us whether or not is acceptable. Also, remove stuff we don't like # such as leading / trailing space. @@ -13,14 +11,11 @@ class TextSentinel end def initialize(text, opts=nil) - if text.present? - @text = Iconv.new('UTF-8//IGNORE', 'UTF-8').iconv(text.dup) - end - @opts = opts || {} - if @text.present? - @text.strip! + if text.present? + @text = text.encode('UTF-8', invalid: :replace, undef: :replace, replace: '') + @text.strip! @text.gsub!(/ +/m, ' ') if @opts[:remove_interior_spaces] end end diff --git a/spec/components/text_sentinel_spec.rb b/spec/components/text_sentinel_spec.rb index 2b50aef8384..a257c8fffc2 100644 --- a/spec/components/text_sentinel_spec.rb +++ b/spec/components/text_sentinel_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' require 'text_sentinel' -require 'iconv' describe TextSentinel do @@ -100,4 +99,4 @@ describe TextSentinel do end -end \ No newline at end of file +end