Class: Slocks::RichTextSectionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/slocks/rich_text_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ RichTextSectionBuilder

Returns a new instance of RichTextSectionBuilder.



52
53
54
# File 'lib/slocks/rich_text_builder.rb', line 52

def initialize
  @elements = []
end

Instance Attribute Details

#elements ⇒ Object (readonly)

Returns the value of attribute elements.



50
51
52
# File 'lib/slocks/rich_text_builder.rb', line 50

def elements
  @elements
end

Instance Method Details

#broadcast(range:) ⇒ Object



98
99
100
# File 'lib/slocks/rich_text_builder.rb', line 98

def broadcast(range:)
  @elements << { type: "broadcast", range: range }
end

#channel(channel_id) ⇒ Object



79
80
81
# File 'lib/slocks/rich_text_builder.rb', line 79

def channel(channel_id)
  @elements << { type: "channel", channel_id: channel_id }
end

#date(timestamp, format:, fallback: nil, link: nil) ⇒ Object



91
92
93
94
95
96
# File 'lib/slocks/rich_text_builder.rb', line 91

def date(timestamp, format:, fallback: nil, link: nil)
  element = { type: "date", timestamp: timestamp, format: format }
  element[:fallback] = fallback if fallback
  element[:link] = link if link
  @elements << element
end

#emoji(name) ⇒ Object



75
76
77
# File 'lib/slocks/rich_text_builder.rb', line 75

def emoji(name)
  @elements << { type: "emoji", name: name }
end


67
68
69
70
71
72
73
# File 'lib/slocks/rich_text_builder.rb', line 67

def link(url, text: nil, unsafe: nil, style: nil)
  element = { type: "link", url: url }
  element[:text] = text if text
  element[:unsafe] = unsafe if unsafe
  element[:style] = style if style
  @elements << element
end

#text(text, bold: nil, italic: nil, strike: nil, code: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/slocks/rich_text_builder.rb', line 56

def text(text, bold: nil, italic: nil, strike: nil, code: nil)
  element = { type: "text", text: text }
  style = {}
  style[:bold] = true if bold
  style[:italic] = true if italic
  style[:strike] = true if strike
  style[:code] = true if code
  element[:style] = style unless style.empty?
  @elements << element
end

#user(user_id) ⇒ Object



83
84
85
# File 'lib/slocks/rich_text_builder.rb', line 83

def user(user_id)
  @elements << { type: "user", user_id: user_id }
end

#usergroup(usergroup_id) ⇒ Object



87
88
89
# File 'lib/slocks/rich_text_builder.rb', line 87

def usergroup(usergroup_id)
  @elements << { type: "usergroup", usergroup_id: usergroup_id }
end