Class: Zircon::Message
- Inherits:
-
Object
- Object
- Zircon::Message
- Defined in:
- lib/zircon/message.rb,
lib/zircon/message/patterns.rb
Defined Under Namespace
Modules: Patterns
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #body ⇒ Object
- #from ⇒ Object
-
#initialize(text) ⇒ Message
constructor
A new instance of Message.
- #params ⇒ Object
- #to ⇒ Object
- #to_hash ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(text) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/zircon/message.rb', line 7 def initialize(text) if match = Patterns::MESSAGE_PATTERN.match(text) @text = text @prefix = match[1] @command = match[2] @rest = match[3..-1] else raise ArgumentError.new("Invalid message: #{text}") end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/zircon/message.rb', line 5 def command @command end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/zircon/message.rb', line 5 def prefix @prefix end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/zircon/message.rb', line 5 def raw @raw end |
Instance Method Details
#body ⇒ Object
41 42 43 |
# File 'lib/zircon/message.rb', line 41 def body params[1] end |
#from ⇒ Object
31 32 33 34 35 |
# File 'lib/zircon/message.rb', line 31 def from @from ||= begin @prefix && @prefix.split("!").first end end |
#params ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zircon/message.rb', line 45 def params @params ||= begin params = [] case when !@rest[0].empty? middle, trailer, = *@rest params = middle.split(" ") when !@rest[2].nil? && !@rest[2].empty? middle, trailer, = *@rest[2, 2] params = middle.split(" ") when @rest[1] trailer = @rest[1] when @rest[3] trailer = @rest[3] end params << trailer if trailer params end end |
#to ⇒ Object
37 38 39 |
# File 'lib/zircon/message.rb', line 37 def to params[0] end |
#to_hash ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/zircon/message.rb', line 18 def to_hash { body: body, from: from, to: to, type: type, } end |
#type ⇒ Object
27 28 29 |
# File 'lib/zircon/message.rb', line 27 def type @type ||= @command.to_s.downcase end |