Module: MosEisley::S3PO::BlockKit

Defined in:
lib/s3po/blockkit.rb

Constant Summary collapse

VERSION =
'20220224'.freeze

Class Method Summary collapse

Class Method Details

.con_text(txt, type = :mrkdwn) ⇒ Hash

Returns Block Kit section object.

Parameters:

  • txt (String)
  • type (Symbol) (defaults to: :mrkdwn)

    :plain | :emoji | :mrkdwn

Returns:

  • (Hash)

    Block Kit section object



13
14
15
16
17
18
19
20
# File 'lib/s3po/blockkit.rb', line 13

def self.con_text(txt, type = :mrkdwn)
  {
    type: :context,
    elements: [
      text(txt, type),
    ]
  }
end

.emoji_text(txt) ⇒ Hash

Returns Block Kit plain_text object with emoji:true.

Parameters:

  • txt (String)

Returns:

  • (Hash)

    Block Kit plain_text object with emoji:true



76
77
78
# File 'lib/s3po/blockkit.rb', line 76

def self.emoji_text(txt)
  text(txt, :emoji)
end

.header(txt) ⇒ Hash

Returns Block Kit header object.

Parameters:

  • txt (String)

Returns:

  • (Hash)

    Block Kit header object



24
25
26
27
28
29
# File 'lib/s3po/blockkit.rb', line 24

def self.header(txt)
  {
    type: :header,
    text: text(txt, :emoji),
  }
end

.option(value, txt, type = :mrkdwn) ⇒ Hash

Returns Block Kit option object.

Parameters:

  • value (String)

    string that will be passed to the app when selected

  • txt (String)
  • type (Symbol) (defaults to: :mrkdwn)

    :plain_text | :emoji | :mrkdwn

Returns:

  • (Hash)

    Block Kit option object



84
85
86
87
88
89
90
# File 'lib/s3po/blockkit.rb', line 84

def self.option(value, txt, type = :mrkdwn)
  t = MosEisley::S3PO::BlockKit.text(txt, type)
  {
    text: t,
    value: value,
  }
end

.plain_text(txt) ⇒ Hash

Returns Block Kit plain_text object with emoji:false.

Parameters:

  • txt (String)

Returns:

  • (Hash)

    Block Kit plain_text object with emoji:false



70
71
72
# File 'lib/s3po/blockkit.rb', line 70

def self.plain_text(txt)
  text(txt, :plain)
end

.sec_fields(fields, type = :mrkdwn) ⇒ Hash

Returns Block Kit section object.

Parameters:

  • fields (Array<String>)
  • type (Symbol) (defaults to: :mrkdwn)

    :plain | :emoji | :mrkdwn

Returns:

  • (Hash)

    Block Kit section object



44
45
46
47
48
49
# File 'lib/s3po/blockkit.rb', line 44

def self.sec_fields(fields, type = :mrkdwn)
  {
    type: :section,
    fields: fields.map{ |txt| text(txt, type) },
  }
end

.sec_text(txt, type = :mrkdwn) ⇒ Hash

Returns Block Kit section object.

Parameters:

  • txt (String)
  • type (Symbol) (defaults to: :mrkdwn)

    :plain | :emoji | :mrkdwn

Returns:

  • (Hash)

    Block Kit section object



34
35
36
37
38
39
# File 'lib/s3po/blockkit.rb', line 34

def self.sec_text(txt, type = :mrkdwn)
  {
    type: :section,
    text: text(txt, type),
  }
end

.text(txt, type = :mrkdwn) ⇒ Hash

Returns Block Kit text object.

Parameters:

  • txt (String)
  • type (Symbol) (defaults to: :mrkdwn)

    :plain | :emoji | :mrkdwn

Returns:

  • (Hash)

    Block Kit text object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/s3po/blockkit.rb', line 54

def self.text(txt, type = :mrkdwn)
  obj = {text: txt}
  case type
  when :mrkdwn
    obj[:type] = type
  when :emoji
    obj[:emoji] = true
  else
    obj[:emoji] = false
  end
  obj[:type] ||= :plain_text
  obj
end