lib/cucumber/messages/location.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 Location message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    #
    # *
    #  Points to a line and a column in a text file
    ##
    class Location < Message
      attr_reader :line

      attr_reader :column

      def initialize(
        line: 0,
        column: nil
      )
        @line = line
        @column = column
        super()
      end

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

        new(
          line: hash[:line],
          column: hash[:column]
        )
      end
    end
  end
end