Class: Line::Bot::V2::MessagingApi::FlexText

Inherits:
FlexComponent show all
Defined in:
lib/line/bot/v2/messaging_api/model/flex_text.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flex: nil, text: nil, size: nil, align: nil, gravity: nil, color: nil, weight: nil, style: nil, decoration: nil, wrap: nil, line_spacing: nil, margin: nil, position: nil, offset_top: nil, offset_bottom: nil, offset_start: nil, offset_end: nil, action: nil, max_lines: nil, contents: nil, adjust_mode: nil, scaling: nil, **dynamic_attributes) ⇒ FlexText

Returns a new instance of FlexText.

Parameters:

  • flex (Integer, nil) (defaults to: nil)
  • text (String, nil) (defaults to: nil)
  • size (String, nil) (defaults to: nil)
  • align (String, nil) (defaults to: nil)

    (‘start’|‘end’|‘center’)

  • gravity (String, nil) (defaults to: nil)

    (‘top’|‘bottom’|‘center’)

  • color (String, nil) (defaults to: nil)
  • weight (String, nil) (defaults to: nil)

    (‘regular’|‘bold’)

  • style (String, nil) (defaults to: nil)

    (‘normal’|‘italic’)

  • decoration (String, nil) (defaults to: nil)

    (‘none’|‘underline’|‘line-through’)

  • wrap (Boolean, nil) (defaults to: nil)
  • line_spacing (String, nil) (defaults to: nil)
  • margin (String, nil) (defaults to: nil)
  • position (String, nil) (defaults to: nil)

    (‘relative’|‘absolute’)

  • offset_top (String, nil) (defaults to: nil)
  • offset_bottom (String, nil) (defaults to: nil)
  • offset_start (String, nil) (defaults to: nil)
  • offset_end (String, nil) (defaults to: nil)
  • action (Action, Hash[Symbol, untyped], nil) (defaults to: nil)
  • max_lines (Integer, nil) (defaults to: nil)
  • contents (Array[FlexSpan, Hash[Symbol, untyped]], nil) (defaults to: nil)
  • adjust_mode (String, nil) (defaults to: nil)

    (‘shrink-to-fit’)

  • scaling (Boolean, nil) (defaults to: nil)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 109

def initialize(
  flex: nil,
  text: nil,
  size: nil,
  align: nil,
  gravity: nil,
  color: nil,
  weight: nil,
  style: nil,
  decoration: nil,
  wrap: nil,
  line_spacing: nil,
  margin: nil,
  position: nil,
  offset_top: nil,
  offset_bottom: nil,
  offset_start: nil,
  offset_end: nil,
  action: nil,
  max_lines: nil,
  contents: nil,
  adjust_mode: nil,
  scaling: nil,
  **dynamic_attributes
)
  @type = "text"
  
  @flex = flex
  @text = text
  @size = size
  @align = align
  @gravity = gravity
  @color = color
  @weight = weight
  @style = style
  @decoration = decoration
  @wrap = wrap
  @line_spacing = line_spacing
  @margin = margin
  @position = position
  @offset_top = offset_top
  @offset_bottom = offset_bottom
  @offset_start = offset_start
  @offset_end = offset_end
  @action = action.is_a?(Line::Bot::V2::MessagingApi::Action) || action.nil? ? action : Line::Bot::V2::MessagingApi::Action.create(**action) # steep:ignore
  @max_lines = max_lines
  @contents = contents&.map do |item|
    if item.is_a?(Hash)
      Line::Bot::V2::MessagingApi::FlexSpan.create(**item) # steep:ignore InsufficientKeywordArguments
    else
      item
    end
  end
  @adjust_mode = adjust_mode
  @scaling = scaling

  dynamic_attributes.each do |key, value|
    self.class.attr_accessor key

    if value.is_a?(Hash)
      struct_klass = Struct.new(*value.keys.map(&:to_sym))
      struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
      instance_variable_set("@#{key}", struct_klass.new(*struct_values))
    else
      instance_variable_set("@#{key}", value)
    end
  end
end

Instance Attribute Details

#actionAction?

Returns:



73
74
75
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 73

def action
  @action
end

#adjust_modeString?

Returns (‘shrink-to-fit’).

Returns:

  • (String, nil)

    (‘shrink-to-fit’)



82
83
84
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 82

def adjust_mode
  @adjust_mode
end

#alignString?

Returns (‘start’|‘end’|‘center’).

Returns:

  • (String, nil)

    (‘start’|‘end’|‘center’)



31
32
33
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 31

def align
  @align
end

#colorString?

Returns:

  • (String, nil)


37
38
39
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 37

def color
  @color
end

#contentsArray[FlexSpan]?

Returns:



79
80
81
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 79

def contents
  @contents
end

#decorationString?

Returns (‘none’|‘underline’|‘line-through’).

Returns:

  • (String, nil)

    (‘none’|‘underline’|‘line-through’)



46
47
48
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 46

def decoration
  @decoration
end

#flexInteger?

Returns:

  • (Integer, nil)


22
23
24
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 22

def flex
  @flex
end

#gravityString?

Returns (‘top’|‘bottom’|‘center’).

Returns:

  • (String, nil)

    (‘top’|‘bottom’|‘center’)



34
35
36
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 34

def gravity
  @gravity
end

#line_spacingString?

Returns:

  • (String, nil)


52
53
54
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 52

def line_spacing
  @line_spacing
end

#marginString?

Returns:

  • (String, nil)


55
56
57
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 55

def margin
  @margin
end

#max_linesInteger?

Returns:

  • (Integer, nil)


76
77
78
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 76

def max_lines
  @max_lines
end

#offset_bottomString?

Returns:

  • (String, nil)


64
65
66
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 64

def offset_bottom
  @offset_bottom
end

#offset_endString?

Returns:

  • (String, nil)


70
71
72
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 70

def offset_end
  @offset_end
end

#offset_startString?

Returns:

  • (String, nil)


67
68
69
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 67

def offset_start
  @offset_start
end

#offset_topString?

Returns:

  • (String, nil)


61
62
63
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 61

def offset_top
  @offset_top
end

#positionString?

Returns (‘relative’|‘absolute’).

Returns:

  • (String, nil)

    (‘relative’|‘absolute’)



58
59
60
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 58

def position
  @position
end

#scalingBoolean?

Returns:

  • (Boolean, nil)


85
86
87
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 85

def scaling
  @scaling
end

#sizeString?

Returns:

  • (String, nil)


28
29
30
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 28

def size
  @size
end

#styleString?

Returns (‘normal’|‘italic’).

Returns:

  • (String, nil)

    (‘normal’|‘italic’)



43
44
45
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 43

def style
  @style
end

#textString?

Returns:

  • (String, nil)


25
26
27
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 25

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 19

def type
  @type
end

#weightString?

Returns (‘regular’|‘bold’).

Returns:

  • (String, nil)

    (‘regular’|‘bold’)



40
41
42
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 40

def weight
  @weight
end

#wrapBoolean?

Returns:

  • (Boolean, nil)


49
50
51
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 49

def wrap
  @wrap
end

Class Method Details

.create(args) ⇒ Line::Bot::V2::MessagingApi::FlexText

Create an instance of the class from a hash

Parameters:

  • args (Hash)

    Hash containing all the required attributes

Returns:



181
182
183
184
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 181

def self.create(args) # steep:ignore
  symbolized_args = Line::Bot::V2::Utils.deep_symbolize(args)
  return new(**symbolized_args) # steep:ignore
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if the objects are equal, false otherwise.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Boolean)

    true if the objects are equal, false otherwise



188
189
190
191
192
193
194
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 188

def ==(other)
  return false unless self.class == other.class

  instance_variables.all? do |var|
      instance_variable_get(var) == other.instance_variable_get(var)
  end
end

#hashInteger

Returns Hash code of the object.

Returns:

  • (Integer)

    Hash code of the object



197
198
199
# File 'lib/line/bot/v2/messaging_api/model/flex_text.rb', line 197

def hash
  [self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
end