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



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



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

def action
  @action
end

#adjust_modeString?



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

def adjust_mode
  @adjust_mode
end

#colorString?



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

def color
  @color
end

#flexInteger?



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

def flex
  @flex
end

#gravityString?



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

def gravity
  @gravity
end

#heightString?



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

def height
  @height
end

#marginString?



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

def margin
  @margin
end

#offset_bottomString?



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

def offset_bottom
  @offset_bottom
end

#offset_endString?



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

def offset_end
  @offset_end
end

#offset_startString?



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

def offset_start
  @offset_start
end

#offset_topString?



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

def offset_top
  @offset_top
end

#positionString?



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

def position
  @position
end

#scalingBoolean?



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

def scaling
  @scaling
end

#styleString?



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



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



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



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