lib/cucumber/messages/parameter_type.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 ParameterType message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    ##
    class ParameterType < Message
      ##
      # The name is unique, so we don't need an id.
      ##
      attr_reader :name

      attr_reader :regular_expressions

      attr_reader :prefer_for_regular_expression_match

      attr_reader :use_for_snippets

      attr_reader :id

      attr_reader :source_reference

      def initialize(
        name: '',
        regular_expressions: [],
        prefer_for_regular_expression_match: false,
        use_for_snippets: false,
        id: '',
        source_reference: nil
      )
        @name = name
        @regular_expressions = regular_expressions
        @prefer_for_regular_expression_match = prefer_for_regular_expression_match
        @use_for_snippets = use_for_snippets
        @id = id
        @source_reference = source_reference
        super()
      end

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

        new(
          name: hash[:name],
          regular_expressions: hash[:regularExpressions],
          prefer_for_regular_expression_match: hash[:preferForRegularExpressionMatch],
          use_for_snippets: hash[:useForSnippets],
          id: hash[:id],
          source_reference: SourceReference.from_h(hash[:sourceReference])
        )
      end
    end
  end
end