Sha256: e549837d76aa20c211958c692da65717365176a0c4c2bb98c58bb4878bafffd9

Contents?: true

Size: 1.43 KB

Versions: 95

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

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"
        end
      end

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

      def location_to_s
        return if nil_or_zero?(line) && nil_or_zero?(column)

        "#{line}:#{column}"
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 6 rubygems

Version Path
nokogiri-1.16.6-x64-mingw32 lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.6-x64-mingw-ucrt lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.6-java lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.6-arm64-darwin lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.6-arm-linux lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.6-aarch64-linux lib/nokogiri/xml/syntax_error.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/xml/syntax_error.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4 lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x86_64-linux lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x86_64-darwin lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x86-mingw32 lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x86-linux lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x64-mingw32 lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-x64-mingw-ucrt lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-java lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-arm64-darwin lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-arm-linux lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.4-aarch64-linux lib/nokogiri/xml/syntax_error.rb
nokogiri-1.16.3 lib/nokogiri/xml/syntax_error.rb