Class: BlockKit::Elements::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/block_kit/elements/image.rb

Constant Summary collapse

MAX_ALT_TEXT_LENGTH =
2000
MAX_IMAGE_URL_LENGTH =
3000

Instance Method Summary collapse

Methods inherited from Base

#==, fix, #fix_validation_errors, #fix_validation_errors!, fixes, inherited, #initialize, inspect, #inspect, #pretty_print, #to_json

Constructor Details

This class inherits a constructor from BlockKit::Base

Instance Method Details

#as_jsonObject



38
39
40
41
42
43
44
# File 'lib/block_kit/elements/image.rb', line 38

def as_json(*)
  super.merge(
    alt_text: alt_text,
    image_url: image_url,
    slack_file: slack_file&.as_json
  ).compact
end

#slack_file(attrs = {}) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
# File 'lib/block_kit/elements/image.rb', line 27

def slack_file(attrs = {})
  attrs = attrs.with_indifferent_access
  return super() unless attrs.key?(:id) || attrs.key?(:url)

  raise ArgumentError, "mutually exclusive keywords: :id, :url" if attrs.key?(:id) && attrs.key?(:url)

  self.slack_file = Composition::SlackFile.new(**attrs.slice(:id, :url))

  self
end