Class: Whatsapp::MessageTemplates::Component::Base

Inherits:
Object
  • Object
show all
Includes:
ValueObject
Defined in:
lib/ruby/whatsapp/message_templates/component/base.rb

Overview

Shared behaviour for every component a template can declare.

Holds the template's parameter_format, which every component accepts even though only Header and Body use it. Uniformity is deliberate: .build can then thread the format down without knowing which components care, and carousel cards can pass it on to their own nested components.

Each subclass owns its wire type as Defaults::TYPE, so the TYPES registry maps kind to class only and there is one source of truth.

Direct Known Subclasses

Body, Buttons, Carousel, Footer, Header, LimitedTimeOffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValueObject

included, #serialize

Constructor Details

#initialize(parameter_format: ParameterFormats::POSITIONAL) ⇒ Base

Returns a new instance of Base.

Parameters:

  • parameter_format (String, Symbol) (defaults to: ParameterFormats::POSITIONAL)

    The owning template's placeholder style. Defaults to Meta's own default.



32
33
34
# File 'lib/ruby/whatsapp/message_templates/component/base.rb', line 32

def initialize(parameter_format: ParameterFormats::POSITIONAL)
  @parameter_format = ParameterFormats.normalize(parameter_format)
end

Instance Attribute Details

#example_errorObject (readonly)

Returns the value of attribute example_error.



26
27
28
# File 'lib/ruby/whatsapp/message_templates/component/base.rb', line 26

def example_error
  @example_error
end

#parameter_formatString

Returns see ParameterFormats.

Returns:



20
21
22
# File 'lib/ruby/whatsapp/message_templates/component/base.rb', line 20

def parameter_format
  @parameter_format
end

Instance Method Details

#api_typeString

The uppercase value Meta expects in the component's type field.

Returns:

  • (String)


38
39
40
# File 'lib/ruby/whatsapp/message_templates/component/base.rb', line 38

def api_type
  self.class::Defaults::TYPE
end