Class: Codebot::Channel
- Inherits:
-
Serializable
- Object
- Serializable
- Codebot::Channel
- Includes:
- Sanitizers
- Defined in:
- lib/codebot/channel.rb
Overview
This class represents an IRC channel notifications can be delivered to.
Instance Attribute Summary collapse
-
#key ⇒ String?
The key required for joining this channel.
-
#name ⇒ String
The name of this channel.
-
#network ⇒ Network
readonly
The network this channel belongs to.
-
#send_external ⇒ Boolean
Whether to send messages without joining this channel.
Class Method Summary collapse
-
.deserialize(identifier, data) ⇒ Hash
Deserializes a channel.
-
.serialize_as_hash? ⇒ true
To indicate that data is serialized into a hash.
Instance Method Summary collapse
-
#identifier ⇒ String
Returns the string used to identify this channel in configuration files.
-
#identifier_eql?(identifier) ⇒ Boolean
Checks whether the identifier of this channel is equal to another identifier.
-
#initialize(params) ⇒ Channel
constructor
Creates a new channel from the supplied hash.
- #key? ⇒ Boolean
-
#serialize(_conf) ⇒ Array, Hash
Serializes this channel.
-
#set_identifier(identifier, conf) ⇒ Object
Sets network and channel name based on the given identifier.
-
#set_network(network, conf) ⇒ Object
Sets the network for this channel.
-
#update!(params) ⇒ Object
Updates the channel from the supplied hash.
Methods included from Sanitizers
#valid!, #valid_boolean, #valid_channel_key, #valid_channel_name, #valid_endpoint, #valid_host, #valid_identifier, #valid_network, #valid_port, #valid_secret, #valid_string
Methods inherited from Serializable
deserialize_all, serialize_all
Constructor Details
#initialize(params) ⇒ Channel
Creates a new channel from the supplied hash.
30 31 32 |
# File 'lib/codebot/channel.rb', line 30 def initialize(params) update!(params) end |
Instance Attribute Details
#key ⇒ String?
Returns the key required for joining this channel.
18 19 20 |
# File 'lib/codebot/channel.rb', line 18 def key @key end |
#name ⇒ String
Returns the name of this channel.
12 13 14 |
# File 'lib/codebot/channel.rb', line 12 def name @name end |
#network ⇒ Network (readonly)
Returns the network this channel belongs to.
15 16 17 |
# File 'lib/codebot/channel.rb', line 15 def network @network end |
#send_external ⇒ Boolean
Returns whether to send messages without joining this channel.
21 22 23 |
# File 'lib/codebot/channel.rb', line 21 def send_external @send_external end |
Class Method Details
.deserialize(identifier, data) ⇒ Hash
Deserializes a channel.
121 122 123 124 125 126 127 |
# File 'lib/codebot/channel.rb', line 121 def self.deserialize(identifier, data) { identifier: identifier, key: data['key'], send_external: data['send_external'] } end |
.serialize_as_hash? ⇒ true
Returns to indicate that data is serialized into a hash.
130 131 132 |
# File 'lib/codebot/channel.rb', line 130 def self.serialize_as_hash? true end |
Instance Method Details
#identifier ⇒ String
Returns the string used to identify this channel in configuration files.
92 93 94 |
# File 'lib/codebot/channel.rb', line 92 def identifier "#{@network.name}/#{@name}" end |
#identifier_eql?(identifier) ⇒ Boolean
Checks whether the identifier of this channel is equal to another identifier.
85 86 87 |
# File 'lib/codebot/channel.rb', line 85 def identifier_eql?(identifier) self.identifier.casecmp(identifier).zero? end |
#key? ⇒ Boolean
69 70 71 |
# File 'lib/codebot/channel.rb', line 69 def key? !key.to_s.strip.empty? end |
#serialize(_conf) ⇒ Array, Hash
Serializes this channel.
109 110 111 112 113 114 |
# File 'lib/codebot/channel.rb', line 109 def serialize(_conf) [identifier, { 'key' => key, 'send_external' => send_external }] end |
#set_identifier(identifier, conf) ⇒ Object
Sets network and channel name based on the given identifier.
100 101 102 103 |
# File 'lib/codebot/channel.rb', line 100 def set_identifier(identifier, conf) network_name, self.name = identifier.split('/', 2) if identifier set_network(network_name, conf) end |
#set_network(network, conf) ⇒ Object
Sets the network for this channel.
57 58 59 60 61 62 |
# File 'lib/codebot/channel.rb', line 57 def set_network(network, conf) @network = valid! network, valid_network(network, conf), :@network, required: true, required_error: 'channels must have a network', invalid_error: 'invalid channel network %s' end |
#update!(params) ⇒ Object
Updates the channel from the supplied hash.
38 39 40 41 42 43 44 |
# File 'lib/codebot/channel.rb', line 38 def update!(params) set_identifier params[:identifier], params[:config] if params[:identifier] self.name = params[:name] self.key = params[:key] self.send_external = params[:send_external] set_network params[:network], params[:config] end |