Class: Twitch::Channel
- Inherits:
-
Object
- Object
- Twitch::Channel
- Defined in:
- lib/twitch_chatter/models/channel.rb
Overview
Instance Attribute Summary collapse
- #name ⇒ String readonly
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(name, bot: nil) ⇒ Channel
constructor
A new instance of Channel.
- #join {|message| ... } ⇒ nil
-
#leave ⇒ nil
Disconnects from channel and removes all message callbacks.
- #to_s ⇒ String
- #to_sym ⇒ Symbol
- #to_url ⇒ String (also: #link, #href)
Constructor Details
#initialize(name, bot: nil) ⇒ Channel
Returns a new instance of Channel.
14 15 16 17 |
# File 'lib/twitch_chatter/models/channel.rb', line 14 def initialize(name, bot: nil) @name = name.to_sym @bot = bot end |
Instance Attribute Details
#name ⇒ String (readonly)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/twitch_chatter/models/channel.rb', line 8 class Channel # @return [String] attr_reader :name # @param [String, Symbol] name # @param [Bot, nil] bot def initialize(name, bot: nil) @name = name.to_sym @bot = bot end # @yieldparam message [Twitch::Message] # @return [nil] # @example # channel.join do |message| # puts "##{message.channel} #{message.sender}: #{message}" # end def join(&block) @bot.join(@name, &block) end # Disconnects from channel and removes all message callbacks. # @return [nil] def leave @bot.leave(@name) end # @return [Symbol] def to_sym @name end # @return [String] def to_s @name.to_s end # @return [String] def to_url "https://twitch.tv/#{@name}" end alias_method :link, :to_url alias_method :href, :to_url # @param [Channel, String, Symbol] other # @return [Boolean] def ==(other) if other.is_a?(Channel) return @name == other.name end @name == other.to_sym end end |
Instance Method Details
#==(other) ⇒ Boolean
55 56 57 58 59 60 61 |
# File 'lib/twitch_chatter/models/channel.rb', line 55 def ==(other) if other.is_a?(Channel) return @name == other.name end @name == other.to_sym end |
#join {|message| ... } ⇒ nil
25 26 27 |
# File 'lib/twitch_chatter/models/channel.rb', line 25 def join(&block) @bot.join(@name, &block) end |
#leave ⇒ nil
Disconnects from channel and removes all message callbacks.
31 32 33 |
# File 'lib/twitch_chatter/models/channel.rb', line 31 def leave @bot.leave(@name) end |
#to_s ⇒ String
41 42 43 |
# File 'lib/twitch_chatter/models/channel.rb', line 41 def to_s @name.to_s end |
#to_sym ⇒ Symbol
36 37 38 |
# File 'lib/twitch_chatter/models/channel.rb', line 36 def to_sym @name end |
#to_url ⇒ String Also known as: link, href
46 47 48 |
# File 'lib/twitch_chatter/models/channel.rb', line 46 def to_url "https://twitch.tv/#{@name}" end |