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
- #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
32 33 34 |
# File 'lib/zircon/message.rb', line 32 def body params[1] end |
#from ⇒ Object
22 23 24 25 26 |
# File 'lib/zircon/message.rb', line 22 def from @from ||= begin @prefix && @prefix.split("!").first end end |
#params ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zircon/message.rb', line 36 def params @params ||= begin params = [] case when !@rest[0].empty? middle, trailer, = *@rest params = middle.split(" ") when !@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
28 29 30 |
# File 'lib/zircon/message.rb', line 28 def to params[0] end |
#type ⇒ Object
18 19 20 |
# File 'lib/zircon/message.rb', line 18 def type @type ||= @command.to_s.downcase end |