Module: MosEisley::S3PO::BlockKit

Defined in:
lib/s3po/blockkit.rb

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



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

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



65
66
67
# File 'lib/s3po/blockkit.rb', line 65

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



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

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



73
74
75
76
77
78
79
# File 'lib/s3po/blockkit.rb', line 73

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



59
60
61
# File 'lib/s3po/blockkit.rb', line 59

def self.plain_text(txt)
  text(txt, :plain)
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



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

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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/s3po/blockkit.rb', line 43

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