Class: SlackMessage::Dsl::List
- Inherits:
-
Object
- Object
- SlackMessage::Dsl::List
- Defined in:
- lib/slack_message/dsl.rb
Instance Method Summary collapse
- #add(title, value) ⇒ Object
- #any? ⇒ Boolean
-
#initialize ⇒ List
constructor
A new instance of List.
- #render ⇒ Object
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
282 283 284 |
# File 'lib/slack_message/dsl.rb', line 282 def initialize @items = [] end |
Instance Method Details
#add(title, value) ⇒ Object
290 291 292 |
# File 'lib/slack_message/dsl.rb', line 290 def add(title, value) @items.push(["*#{title}*", value]) end |
#any? ⇒ Boolean
286 287 288 |
# File 'lib/slack_message/dsl.rb', line 286 def any? @items.any? end |
#render ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/slack_message/dsl.rb', line 294 def render @items.push([' ', ' ']) if @items.length % 2 == 1 @items.each_slice(2).flat_map do |(first, second)| [ { type: "mrkdwn", text: first[0] }, { type: "mrkdwn", text: second[0] }, { type: "mrkdwn", text: first[1] }, { type: "mrkdwn", text: second[1] }, ] end end |