Class: Slacks::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/slacks/channel.rb

Direct Known Subclasses

GuestChannel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slack, attributes = {}) ⇒ Channel

Returns a new instance of Channel.



5
6
7
8
9
10
11
12
# File 'lib/slacks/channel.rb', line 5

def initialize(slack, attributes={})
  @slack = slack
  @id = attributes["id"]
  @name = attributes["name"]
  @type = :channel
  @type = :group if attributes["is_group"]
  @type = :direct_message if attributes["is_im"]
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/slacks/channel.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/slacks/channel.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/slacks/channel.rb', line 3

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/slacks/channel.rb', line 49

def ==(other)
  self.class == other.class && self.id == other.id
end

#direct_message?Boolean Also known as: dm?, im?

Returns:

  • (Boolean)


29
30
31
# File 'lib/slacks/channel.rb', line 29

def direct_message?
  type == :direct_message
end

#guest?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/slacks/channel.rb', line 41

def guest?
  false
end

#inspectObject



45
46
47
# File 'lib/slacks/channel.rb', line 45

def inspect
  "<Slacks::Channel id=\"#{id}\" name=\"#{name}\">"
end

#private_group?Boolean Also known as: group?, private?

Returns:

  • (Boolean)


35
36
37
# File 'lib/slacks/channel.rb', line 35

def private_group?
  type == :group
end

#reply(*messages) ⇒ Object Also known as: say



14
15
16
17
18
19
20
21
22
# File 'lib/slacks/channel.rb', line 14

def reply(*messages)
  return unless messages.any?

  if messages.first.is_a?(Array)
    reply_many(messages[0])
  else
    reply_one(*messages)
  end
end

#to_sObject



53
54
55
56
57
# File 'lib/slacks/channel.rb', line 53

def to_s
  return name if private?
  return "@#{name}" if direct_message?
  "##{name}"
end

#typingObject



25
26
27
# File 'lib/slacks/channel.rb', line 25

def typing
  slack.typing_on(self)
end