Class: Line::Message::Builder::Flex::Bubble

Inherits:
Base
  • Object
show all
Includes:
HasPartial
Defined in:
lib/line/message/builder/flex/bubble.rb

Overview

Represents a "bubble" container in a LINE Flex Message. A bubble is a self-contained unit of content, structured into optional sections: header, hero (an image or box), body, and footer. Bubbles are the fundamental building blocks for single Flex Messages or for each item in a Carousel container.

Example: Creating a simple bubble with a body

Line::Message::Builder.with do
flex alt_text: "Simple Bubble" do
  bubble do
    body do
      text "Hello, this is a bubble!"
    end
  end
end
end

See also:

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods included from HasPartial

#partial!

Methods inherited from Base

inherited, #method_missing, #quick_reply, #respond_to_missing?, #to_h

Constructor Details

#initialize(context: nil, **options) ⇒ Bubble

Initializes a new Flex Message Bubble container. The provided block is instance-eval'd, allowing DSL methods for defining sections (e.g., #header, #body) to be called.

[context] An optional context for the builder. [option] A hash of options to set instance variables (e.g., :size, :styles). [block] A block to define the sections of this bubble.



78
79
80
81
82
83
84
85
# File 'lib/line/message/builder/flex/bubble.rb', line 78

def initialize(context: nil, **options, &)
  @header = nil
  @hero = nil
  @body = nil
  @footer = nil

  super # Calls Base#initialize, sets options, and evals block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Line::Message::Builder::Base

Instance Method Details

#body(**options) ⇒ Object

Defines the body section of the bubble using a Box component. This is the main content area of the bubble.

[option] Options for the body Box. See Box#initialize. [block] A block to define the contents of the body Box.



128
129
130
# File 'lib/line/message/builder/flex/bubble.rb', line 128

def body(**options, &)
  @body = Box.new(**options, context: context, &)
end

Defines the footer section of the bubble using a Box component.

[option] Options for the footer Box. See Box#initialize. [block] A block to define the contents of the footer Box.



138
139
140
# File 'lib/line/message/builder/flex/bubble.rb', line 138

def footer(**options, &)
  @footer = Box.new(**options, context: context, &)
end

#header(**options) ⇒ Object

Defines the header section of the bubble using a Box component.

[option] Options for the header Box. See Box#initialize. [block] A block to define the contents of the header Box.



93
94
95
# File 'lib/line/message/builder/flex/bubble.rb', line 93

def header(**options, &)
  @header = Box.new(**options, context: context, &)
end

#hero(**options) ⇒ Object

Defines the hero section of the bubble using a Box component. The hero section is typically used for prominent content like a large image or video.

[option] Options for the hero Box. See Box#initialize. [block] A block to define the contents of the hero Box.



104
105
106
# File 'lib/line/message/builder/flex/bubble.rb', line 104

def hero(**options, &)
  @hero = Box.new(**options, context: context, &)
end

#hero_image(url, **options) ⇒ Object

Defines the hero section of the bubble using an Image component. This is a convenience method for common cases where the hero is a single image.

[url] The URL of the image. [option] Options for the Image component. See Image#initialize. [block] An optional block for the Image component (e.g., for an action).



117
118
119
# File 'lib/line/message/builder/flex/bubble.rb', line 117

def hero_image(url, **options, &)
  @hero = Image.new(url, **options, context: context, &)
end