about summary refs log tree commit homepage
path: root/lib/dtas/encoding.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/encoding.rb')
-rw-r--r--lib/dtas/encoding.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/dtas/encoding.rb b/lib/dtas/encoding.rb
index 613e376..bbc6076 100644
--- a/lib/dtas/encoding.rb
+++ b/lib/dtas/encoding.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 all contributors <dtas-all@nongnu.org>
+# Copyright (C) 2018-2020 all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 
@@ -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