lib/cucumber/messages/parse_error.rb



# frozen_string_literal: true

# The code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/codegen/codegen.rb]
module Cucumber
  module Messages
    ##
    # Represents the ParseError message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    ##
    class ParseError < Message
      attr_reader :source

      attr_reader :message

      def initialize(
        source: SourceReference.new,
        message: ''
      )
        @source = source
        @message = message
        super()
      end

      ##
      # Returns a new ParseError from the given hash.
      # If the hash keys are camelCased, they are properly assigned to the
      # corresponding snake_cased attributes.
      #
      #   Cucumber::Messages::ParseError.from_h(some_hash) # => #<Cucumber::Messages::ParseError:0x... ...>
      ##
      def self.from_h(hash)
        return nil if hash.nil?

        new(
          source: SourceReference.from_h(hash[:source]),
          message: hash[:message]
        )
      end
    end
  end
end