Module: SlackFormat

Included in:
EnerbotSlack
Defined in:
lib/modules/slack_format.rb

Overview

Module for regular expressions that are common

Instance Method Summary collapse

Instance Method Details

#attachment_style(text, pretext: 'Test', color: '#e93d94', author: '') ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/modules/slack_format.rb', line 5

def attachment_style(text, pretext: 'Test', color: '#e93d94', author: '')
  attachment = []
  attachment << {
    "color": color,
    "author_name": author,
    "pretext": pretext,
    "text": text
  }
  attachment
end

#channel_pattern(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/modules/slack_format.rb', line 33

def channel_pattern(data)
  match = data.match(/\s(<[#@])?((.*)\|)?(.*?)(>)? (.*?)$/i)
  p match
  unless match.nil?
    channel = match.captures[2] || match.captures[3]
    text = match.captures[5]
    check_ts = channel.match(/(.*)-(\d*\.\d*)/)
    channel = check_ts.captures[0] unless check_ts.nil?
    thread = check_ts.captures[1] unless check_ts.nil?
  end
  [text, channel, thread]
end

#coin_pattern(text) ⇒ Object



16
17
18
19
# File 'lib/modules/slack_format.rb', line 16

def coin_pattern(text)
  check = text.match(/^<@(.*?)>.*(\+\+|--|balance)(.*)/ix)
  !check.nil? ? check.captures : false
end

#hyper_text_pattern(text, type = 'user') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/modules/slack_format.rb', line 21

def hyper_text_pattern(text, type = 'user')
  pattern = case type
            when 'user'
              /<@(.*)>/
            when 'channel'
              /<#(.*)\|(.*)>/
            when 'channel_fix'
              /\s#(.*?)\s/
            end
  text.match(pattern)
end