Class: Slacky::Channel
- Inherits:
-
Object
- Object
- Slacky::Channel
- Defined in:
- lib/slacky/channel.rb
Constant Summary collapse
- @@channels =
{}
- @@bot =
nil
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#name ⇒ Object
Returns the value of attribute name.
-
#purpose ⇒ Object
readonly
Returns the value of attribute purpose.
-
#slack_id ⇒ Object
readonly
Returns the value of attribute slack_id.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .bot=(bot) ⇒ Object
- .channel(channel_data) ⇒ Object
- .find(channel) ⇒ Object
- .group(group_data) ⇒ Object
- .im(channel_id, user) ⇒ Object
Instance Method Summary collapse
- #archive ⇒ Object
- #archived? ⇒ Boolean
- #delete ⇒ Object
- #member? ⇒ Boolean
- #populate_channel(channel) ⇒ Object
- #populate_group(group) ⇒ Object
- #populate_im(slack_id, user) ⇒ Object
- #rename(name) ⇒ Object
- #save ⇒ Object
- #unarchive ⇒ Object
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
3 4 5 |
# File 'lib/slacky/channel.rb', line 3 def members @members end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/slacky/channel.rb', line 4 def name @name end |
#purpose ⇒ Object (readonly)
Returns the value of attribute purpose.
3 4 5 |
# File 'lib/slacky/channel.rb', line 3 def purpose @purpose end |
#slack_id ⇒ Object (readonly)
Returns the value of attribute slack_id.
3 4 5 |
# File 'lib/slacky/channel.rb', line 3 def slack_id @slack_id end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
3 4 5 |
# File 'lib/slacky/channel.rb', line 3 def topic @topic end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/slacky/channel.rb', line 3 def type @type end |
Class Method Details
.bot=(bot) ⇒ Object
9 10 11 |
# File 'lib/slacky/channel.rb', line 9 def self.bot=(bot) @@bot = bot end |
.channel(channel_data) ⇒ Object
24 25 26 |
# File 'lib/slacky/channel.rb', line 24 def self.channel(channel_data) Channel.new.populate_channel(channel_data).save end |
.find(channel) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/slacky/channel.rb', line 13 def self.find(channel) return nil unless channel return channel.map { |c| Channel.find c }.compact if channel.is_a? Array return channel if channel.is_a? Channel @@channels[channel] end |
.group(group_data) ⇒ Object
28 29 30 |
# File 'lib/slacky/channel.rb', line 28 def self.group(group_data) Channel.new.populate_group(group_data).save end |
.im(channel_id, user) ⇒ Object
20 21 22 |
# File 'lib/slacky/channel.rb', line 20 def self.im(channel_id, user) Channel.new.populate_im(channel_id, user).save end |
Instance Method Details
#archive ⇒ Object
36 37 38 |
# File 'lib/slacky/channel.rb', line 36 def archive @archived = true end |
#archived? ⇒ Boolean
32 33 34 |
# File 'lib/slacky/channel.rb', line 32 def archived? @archived end |
#delete ⇒ Object
44 45 46 47 48 |
# File 'lib/slacky/channel.rb', line 44 def delete @@channels.delete @slack_id @@channels.delete "##{@name}" @@channels.delete "@#{@user.username}" if @user end |
#member? ⇒ Boolean
56 57 58 59 60 61 62 63 |
# File 'lib/slacky/channel.rb', line 56 def member? case @type when :channel ; @member when :group ; @members[@@bot.slack_id] when :im ; true else raise "Unknown channel type: #{@type}" end end |
#populate_channel(channel) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/slacky/channel.rb', line 72 def populate_channel(channel) populate channel @type = :channel @member = channel.is_member self end |
#populate_group(group) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/slacky/channel.rb', line 79 def populate_group(group) populate group @type = :group @members = User.find group.members self end |
#populate_im(slack_id, user) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/slacky/channel.rb', line 86 def populate_im(slack_id, user) @type = :im @slack_id = slack_id @user = user self end |
#rename(name) ⇒ Object
50 51 52 53 54 |
# File 'lib/slacky/channel.rb', line 50 def rename(name) @@channels.delete "##{@name}" @name = name @@channels["##{@name}"] = self end |
#save ⇒ Object
65 66 67 68 69 70 |
# File 'lib/slacky/channel.rb', line 65 def save @@channels[@slack_id] = self @@channels["##{@name}"] = self if @name @@channels["@#{@user.username}"] = self if @user self end |
#unarchive ⇒ Object
40 41 42 |
# File 'lib/slacky/channel.rb', line 40 def unarchive @archived = false end |