class Slack::BlockKit::CompositionObjects::Option

Attributes

description[R]
text[R]
url[R]
value[R]

Public Class Methods

[](hash) click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 10
def self.[](hash)
  new.tap do |object|
    object.text = hash.fetch(:text)
    object.value = hash.fetch(:value)
    object.description = hash[:description] if hash.key?(:description)
    object.url = hash[:url] if hash.key?(:url)
  end
end

Public Instance Methods

description=(obj) click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 33
def description=(obj)
  raise TypeError, 'description must be a Text Object' unless obj.is_a?(Text)
  raise TypeError, 'description must be plain_text' unless obj.type == :plain_text
  raise RangeError, 'description is max 75 characters' unless obj.text.size <= 75

  @description = obj
end
text=(obj) click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 19
def text=(obj)
  raise TypeError, 'text must be a Text Object' unless obj.is_a?(Text)
  raise RangeError, 'text is max 75 characters' unless obj.text.size <= 75

  @text = obj
end
to_h() click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 48
def to_h
  { text: text.to_h,
    value: value,
    description: description&.to_h,
    url: url }.compact
end
url=(obj) click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 41
def url=(obj)
  raise TypeError, 'url must be a string' unless url.respond_to?(:to_str)
  raise RangeError, 'url is max 3000 characters' unless url.size <= 3000

  @url = url.to_s
end
value=(obj) click to toggle source
# File lib/slack/block_kit/composition_objects/option.rb, line 26
def value=(obj)
  raise TypeError, 'value must be a string' unless obj.respond_to?(:to_str)
  raise RangeError, 'value is max 75 characters' unless obj.size <= 75

  @value = obj.to_s
end