Class: Line::Bot::V2::MessagingApi::FlexButton

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flex: nil, color: nil, style: nil, action:, gravity: nil, margin: nil, position: nil, offset_top: nil, offset_bottom: nil, offset_start: nil, offset_end: nil, height: nil, adjust_mode: nil, scaling: nil, **dynamic_attributes) ⇒ FlexButton

Returns a new instance of FlexButton.

Parameters:

  • flex (Integer, nil) (defaults to: nil)
  • color (String, nil) (defaults to: nil)
  • style (String, nil) (defaults to: nil)

    (‘primary’|‘secondary’|‘link’)

  • action (Action, Hash[Symbol, untyped])
  • gravity (String, nil) (defaults to: nil)

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

  • 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)
  • height (String, nil) (defaults to: nil)

    (‘md’|‘sm’)

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

    (‘shrink-to-fit’)

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


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/line/bot/v2/messaging_api/model/flex_button.rb', line 77

def initialize(
  flex: nil,
  color: nil,
  style: nil,
  action:,
  gravity: nil,
  margin: nil,
  position: nil,
  offset_top: nil,
  offset_bottom: nil,
  offset_start: nil,
  offset_end: nil,
  height: nil,
  adjust_mode: nil,
  scaling: nil,
  **dynamic_attributes
)
  @type = "button"
  
  @flex = flex
  @color = color
  @style = style
  @action = action.is_a?(Line::Bot::V2::MessagingApi::Action) ? action : Line::Bot::V2::MessagingApi::Action.create(**action) # steep:ignore
  @gravity = gravity
  @margin = margin
  @position = position
  @offset_top = offset_top
  @offset_bottom = offset_bottom
  @offset_start = offset_start
  @offset_end = offset_end
  @height = height
  @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:



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

def action
  @action
end

#adjust_modeString?

Returns (‘shrink-to-fit’).

Returns:

  • (String, nil)

    (‘shrink-to-fit’)



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

def adjust_mode
  @adjust_mode
end

#colorString?

Returns:

  • (String, nil)


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

def color
  @color
end

#flexInteger?

Returns:

  • (Integer, nil)


22
23
24
# File 'lib/line/bot/v2/messaging_api/model/flex_button.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_button.rb', line 34

def gravity
  @gravity
end

#heightString?

Returns (‘md’|‘sm’).

Returns:

  • (String, nil)

    (‘md’|‘sm’)



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

def height
  @height
end

#marginString?

Returns:

  • (String, nil)


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

def margin
  @margin
end

#offset_bottomString?

Returns:

  • (String, nil)


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

def offset_bottom
  @offset_bottom
end

#offset_endString?

Returns:

  • (String, nil)


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

def offset_end
  @offset_end
end

#offset_startString?

Returns:

  • (String, nil)


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

def offset_start
  @offset_start
end

#offset_topString?

Returns:

  • (String, nil)


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

def offset_top
  @offset_top
end

#positionString?

Returns (‘relative’|‘absolute’).

Returns:

  • (String, nil)

    (‘relative’|‘absolute’)



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

def position
  @position
end

#scalingBoolean?

Returns:

  • (Boolean, nil)


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

def scaling
  @scaling
end

#styleString?

Returns (‘primary’|‘secondary’|‘link’).

Returns:

  • (String, nil)

    (‘primary’|‘secondary’|‘link’)



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

def style
  @style
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

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

Create an instance of the class from a hash

Parameters:

  • args (Hash)

    Hash containing all the required attributes

Returns:



127
128
129
130
# File 'lib/line/bot/v2/messaging_api/model/flex_button.rb', line 127

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



134
135
136
137
138
139
140
# File 'lib/line/bot/v2/messaging_api/model/flex_button.rb', line 134

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



143
144
145
# File 'lib/line/bot/v2/messaging_api/model/flex_button.rb', line 143

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