about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-09-29 02:31:08 +0000
committerEric Wong <e@80x24.org>2020-09-29 03:01:49 +0000
commit63b9c52697a579f53fefc476bcc630420de422ac (patch)
tree113bc85a252017f0e154225ea3f10ce099a8865e
parent0f248206429674778e1c6837a188438af362ef50 (diff)
downloaddtas-master.tar.gz
Ruby case/when is not like C with fall-through, so we can't
rely on fall-through behavior to use CharlockHolmes to detect
legacy encodings.
-rw-r--r--lib/dtas/encoding.rb15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/dtas/encoding.rb b/lib/dtas/encoding.rb
index dad54af..bbc6076 100644
--- a/lib/dtas/encoding.rb
+++ b/lib/dtas/encoding.rb
@@ -11,15 +11,14 @@ module DTAS::Encoding # :nodoc:
 private
 
   def try_enc_harder(str, enc, old) # :nodoc:
+    begin
+      require 'charlock_holmes'
+      @charlock_holmes = CharlockHolmes::EncodingDetector.new
+    rescue LoadError
+      @charlock_holmes = false
+    end if @charlock_holmes.nil?
+
     case @charlock_holmes
-    when nil
-      begin
-        require 'charlock_holmes'
-        @charlock_holmes = CharlockHolmes::EncodingDetector.new
-      rescue LoadError
-        warn "`charlock_holmes` gem not available for encoding detection"
-        @charlock_holmes = false
-      end
     when false
       enc_fallback(str, enc, old)
     else