Class: Slack::BlockKit::Layout::RichText::RichTextElements::Link

Inherits:
Object
  • Object
show all
Includes:
StyleHelper
Defined in:
lib/slack/block_kit/layout/rich_text/rich_text_elements/link.rb

Overview

Constant Summary collapse

TYPE =
'link'
VALID_STYLES =
%w[bold italic strike code].freeze

Instance Method Summary collapse

Methods included from StyleHelper

#styles_as_json, #validate_styles

Constructor Details

#initialize(url:, text: nil, unsafe: nil, styles: []) ⇒ Link

Returns a new instance of Link.



14
15
16
17
18
19
20
# File 'lib/slack/block_kit/layout/rich_text/rich_text_elements/link.rb', line 14

def initialize(url:, text: nil, unsafe: nil, styles: [])
  @url = url
  @text = text
  @unsafe = unsafe
  @styles = styles
  validate_styles(styles, VALID_STYLES)
end

Instance Method Details

#as_jsonObject



22
23
24
25
26
27
28
29
30
# File 'lib/slack/block_kit/layout/rich_text/rich_text_elements/link.rb', line 22

def as_json(*)
  {
    type: TYPE,
    url: @url,
    text: @text,
    unsafe: @unsafe,
    style: styles_as_json(@styles)
  }.compact
end