    # File lib/plugins/encoding.rb, line 5
      def self.encode text, encoding
        return text unless encoding

        if RUBY_VERSION >= '1.9'
          begin
            text = text.encode encoding
          rescue
            # no encodings exception
          end
        else
          begin
            require 'nkf'
          rescue
            return text
          end

          text = case encoding
                 when 'utf-8'
                   NKF.nkf('-w', text)
                 when 'euc-jp'
                   NKF.nkf('-e', text)
                 when 'sjis'
                   NKF.nkf('-s', text)
                 else
                   text
                 end
        end
      end