class Line::Message::Builder::Flex::Carousel
Represents a carousel container in a LINE Flex Message. A carousel is a horizontally scrollable sequence of Bubble components. Each bubble in the carousel is a distinct message unit. Users can swipe left or right to view the different bubbles.
Carousels are ideal for presenting multiple items, such as products, articles, or options, in a compact and interactive way.
Example
Line::Message::Builder.with do flex alt_text: "Product Showcase" do carousel do bubble size: :mega do hero_image "https://example.com/product1.jpg" body { text "Product 1" } end bubble size: :mega do hero_image "https://example.com/product2.jpg" body { text "Product 2" } end end end end
See also:
-
Bubblefor the structure of individual items within the carousel -
HasPartial(included but direct usage onCarouselis limited; partials are more commonly used within bubbles)
Attributes
An array holding the Bubble components that form the items of this carousel.
Public Class Methods
Source
# File lib/line/message/builder/flex/carousel.rb, line 61 def initialize(context: nil, **options, &) @contents = [] # Holds an array of Bubble objects super # Calls Base#initialize, sets options, and evals block end
Initializes a new Flex Message Carousel container. The provided block is instance-eval’d, allowing DSL methods like bubble to be called to add bubbles to the carousel.
- context
-
An optional context for the builder
- options
-
A hash of options (currently none specific to
Carouselitself, but available for future extensions or viaBase) - block
-
A block to define the bubbles within this carousel
Example
carousel = Carousel.new do bubble { body { text "First" } } bubble { body { text "Second" } } end
Line::Message::Builder::Base::new
Public Instance Methods
Source
# File lib/line/message/builder/flex/carousel.rb, line 88 def bubble(**options, &) # The maximum number of bubbles is validated in `to_h` as per LINE API limits. @contents << Line::Message::Builder::Flex::Bubble.new(context: context, **options, &) end
Adds a new Bubble to this carousel’s contents. Each call to this method appends another bubble to the horizontal sequence.
- options
-
Options for the
Bubble(see Bubble#initialize) - block
-
A block to define the sections and content of the
Bubble - return
-
The newly created
Bubbleobject that was added to the carousel
Example
carousel do bubble size: :mega do body { text "Product 1" } end bubble size: :mega do body { text "Product 2" } end end