# 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 TableCell message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    #
    # A cell in a `TableRow`
    ##
    class TableCell < Message
      ##
      # The location of the cell
      ##
      attr_reader :location

      ##
      # The value of the cell
      ##
      attr_reader :value

      def initialize(
        location: Location.new,
        value: ''
      )
        @location = location
        @value = value
        super()
      end

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

        new(
          location: Location.from_h(hash[:location]),
          value: hash[:value]
        )
      end
    end
  end
end
