Sha256: 5959a9ccc27cd7a1d8982815cdfd583b0a14c81bc80a9c6a6113a53bbfa46483

Contents?: true

Size: 1.42 KB

Versions: 165

Compression:

Stored size: 1.42 KB

Contents

module Nokogiri
  module XML
    ###
    # This class provides information about XML SyntaxErrors.  These
    # exceptions are typically stored on Nokogiri::XML::Document#errors.
    class SyntaxError < ::Nokogiri::SyntaxError
      attr_reader :domain
      attr_reader :code
      attr_reader :level
      attr_reader :file
      attr_reader :line
      attr_reader :str1
      attr_reader :str2
      attr_reader :str3
      attr_reader :int1
      attr_reader :column

      ###
      # return true if this is a non error
      def none?
        level == 0
      end

      ###
      # return true if this is a warning
      def warning?
        level == 1
      end

      ###
      # return true if this is an error
      def error?
        level == 2
      end

      ###
      # return true if this error is fatal
      def fatal?
        level == 3
      end

      def to_s
        message = super.chomp
        [location_to_s, level_to_s, message].
          compact.join(": ").
          force_encoding(message.encoding)
      end

      private

      def level_to_s
        case level
        when 3 then "FATAL"
        when 2 then "ERROR"
        when 1 then "WARNING"
        else nil
        end
      end

      def nil_or_zero?(attribute)
        attribute.nil? || attribute.zero?
      end

      def location_to_s
        return nil if nil_or_zero?(line) && nil_or_zero?(column)
        "#{line}:#{column}"
      end
    end
  end
end

Version data entries

165 entries across 141 versions & 14 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.9 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.6 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error 2.rb
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error 3.rb
video_chat_get-0.1.5 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.4 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/nokogiri-1.10.10/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.3 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.2 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.1 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
video_chat_get-0.1.0 vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/xml/syntax_error.rb
nokogiri-1.10.10 lib/nokogiri/xml/syntax_error.rb