Class: BlockKit::Layout::Image

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

Constant Summary collapse

MAX_ALT_TEXT_LENGTH =
2000
MAX_IMAGE_URL_LENGTH =
3000
MAX_TITLE_LENGTH =
2000

Constants inherited from Base

Base::MAX_BLOCK_ID_LENGTH

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize

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::Layout::Base

Instance Method Details

#as_jsonObject



45
46
47
48
49
50
51
52
# File 'lib/block_kit/layout/image.rb', line 45

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

#slack_file(attrs = {}) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
# File 'lib/block_kit/layout/image.rb', line 34

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