Class: Messenger::Components::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/messenger/components/attachment.rb

Instance Method Summary collapse

Constructor Details

#initializeAttachment

Returns a new instance of Attachment.



4
5
6
# File 'lib/messenger/components/attachment.rb', line 4

def initialize
  raise 'This class is abstract!'
end

Instance Method Details

#all_attributesObject



17
18
19
20
# File 'lib/messenger/components/attachment.rb', line 17

def all_attributes
  return instance_values unless defined?(flattened_attributes)
  instance_values.merge! flattened_attributes
end

#allowed_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/messenger/components/attachment.rb', line 26

def allowed_attribute?(attribute)
  self.class::ATTRIBUTES.include?(attribute)
end

#buildObject



8
9
10
11
12
13
14
15
# File 'lib/messenger/components/attachment.rb', line 8

def build
  {
    attachment: {
      type: @type,
      payload: payload
    }
  }
end

#build_elements(elements) ⇒ Object



30
31
32
# File 'lib/messenger/components/attachment.rb', line 30

def build_elements(elements)
  elements.map { |element| element.build } if elements.present?
end

#payloadObject



22
23
24
# File 'lib/messenger/components/attachment.rb', line 22

def payload
  all_attributes.select { |attribute, value| allowed_attribute?(attribute) && value.present? }
end