Class: FDE::Slack::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/message.rb

Constant Summary collapse

BLUE =
'#BDE5F8'.freeze
GREEN =
'#DFF2BF'.freeze
YELLOW =
'#FEEFB3'.freeze
RED =
'#FFBABA'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, fields, author = nil, footer = nil, username = nil) ⇒ Message

Returns a new instance of Message.



16
17
18
19
20
21
22
# File 'lib/slack/message.rb', line 16

def initialize(title, fields, author = nil, footer = nil, username = nil)
  @username = username || 'FDE Slack Notifier'
  @title = title
  @author = author
  @fields = fields
  @footer = footer
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



9
10
11
# File 'lib/slack/message.rb', line 9

def author
  @author
end

#colorObject

Returns the value of attribute color.



9
10
11
# File 'lib/slack/message.rb', line 9

def color
  @color
end

#fieldsObject

Returns the value of attribute fields.



9
10
11
# File 'lib/slack/message.rb', line 9

def fields
  @fields
end

Returns the value of attribute footer.



9
10
11
# File 'lib/slack/message.rb', line 9

def footer
  @footer
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/slack/message.rb', line 9

def title
  @title
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/slack/message.rb', line 9

def username
  @username
end

Instance Method Details

#add_field(field) ⇒ Object



44
45
46
# File 'lib/slack/message.rb', line 44

def add_field(field)
  @fields << field.to_h
end

#error(channel) ⇒ Object



39
40
41
42
# File 'lib/slack/message.rb', line 39

def error(channel)
  @color = RED
  send(channel)
end

#info(channel) ⇒ Object



24
25
26
27
# File 'lib/slack/message.rb', line 24

def info(channel)
  @color = BLUE
  send(channel)
end

#success(channel) ⇒ Object



29
30
31
32
# File 'lib/slack/message.rb', line 29

def success(channel)
  @color = GREEN
  send(channel)
end

#warning(channel) ⇒ Object



34
35
36
37
# File 'lib/slack/message.rb', line 34

def warning(channel)
  @color = YELLOW
  send(channel)
end