Class: Line::Message::Builder::Flex::Icon

Inherits:
Base
  • Object
show all
Includes:
Position::Margin, Position::Offset, Size::Shared
Defined in:
lib/line/message/builder/flex/icon.rb

Overview

Represents an "icon" component in a LINE Flex Message.

Icons render a small image that decorates the text next to them. They are the standard way to build rating stars, labelled metadata rows, and other icon-and-text pairs.

An icon can only be placed in a box whose layout is :baseline. Unlike Image, an icon cannot have an action attached to it.

Example: Rating stars beside a score

Line::Message::Builder.with do
flex alt_text: "Review" do
  bubble do
    body do
      box layout: :baseline do
        icon "https://example.com/star_on.png", size: :sm
        icon "https://example.com/star_on.png", size: :sm
        icon "https://example.com/star_off.png", size: :sm
        text "3.0", size: :sm, margin: :md
      end
    end
  end
end
end

Example: Following the reader's font size

box layout: :baseline do
icon "https://example.com/pin.png", scaling: true
text "Taipei", scaling: true
end

See also:

Instance Attribute Summary collapse

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods included from Size::Shared

included

Methods included from Position::Offset

included

Methods included from Position::Margin

included

Methods inherited from Base

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

Constructor Details

#initialize(url, context: nil, **options) ⇒ Icon

Initializes a new Flex Message Icon component.

[url] The HTTPS URL of the icon image (required) [context] An optional context for the builder (default: nil) [options] A hash of options to set instance variables (e.g., :size, :aspect_ratio, and options from included modules) [block] An optional block for further configuration

Raises RequiredError if url is nil when building the message.

Example

Line::Message::Builder::Flex::Icon.new(
"https://example.com/star.png",
size: :sm
)


97
98
99
100
101
# File 'lib/line/message/builder/flex/icon.rb', line 97

def initialize(url, context: nil, **options, &)
  @url = url # The icon URL is mandatory.

  super(context: context, **options, &)
end

Dynamic Method Handling

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

Instance Attribute Details

#urlObject (readonly)

The URL of the icon image (must be HTTPS). This is a required attribute.



51
52
53
# File 'lib/line/message/builder/flex/icon.rb', line 51

def url
  @url
end