Class: ActionChannels::Message
- Inherits:
-
Object
- Object
- ActionChannels::Message
- Defined in:
- lib/action_channels/message.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#details ⇒ Object
Returns the value of attribute details.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(channel:, type:, author: nil, details: {}) ⇒ Message
constructor
A new instance of Message.
- #to_raw ⇒ Object
Constructor Details
#initialize(channel:, type:, author: nil, details: {}) ⇒ Message
Returns a new instance of Message.
32 33 34 35 36 37 |
# File 'lib/action_channels/message.rb', line 32 def initialize(channel:, type:, author: nil, details: {}) @channel = channel @type = type @author = @details = details end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
5 6 7 |
# File 'lib/action_channels/message.rb', line 5 def @author end |
#channel ⇒ Object
Returns the value of attribute channel.
5 6 7 |
# File 'lib/action_channels/message.rb', line 5 def channel @channel end |
#details ⇒ Object
Returns the value of attribute details.
5 6 7 |
# File 'lib/action_channels/message.rb', line 5 def details @details end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/action_channels/message.rb', line 5 def type @type end |
Class Method Details
.parse(message_raw) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_channels/message.rb', line 13 def parse() command_json = JSON.parse new( channel: command_json['channel'], type: command_json['type'], details: command_json.fetch('details', {}) ) rescue JSON::ParserError => exp raise Errors::NotParseMessage, exp. end |
.parse_and_setup_author(message_raw, author) ⇒ Object
25 26 27 28 29 |
# File 'lib/action_channels/message.rb', line 25 def (, ) command = parse() command. = command end |
Instance Method Details
#to_raw ⇒ Object
39 40 41 |
# File 'lib/action_channels/message.rb', line 39 def to_raw JSON.generate(channel: channel, type: type, details: details) end |