Class: Marvin::IRC::Event
- Inherits:
-
Object
- Object
- Marvin::IRC::Event
- Defined in:
- lib/marvin/irc/event.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#raw_arguments ⇒ Object
Returns the value of attribute raw_arguments.
Instance Method Summary collapse
-
#initialize(name, *args) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #to_incoming_event_name ⇒ Object
- #to_outgoing_event_name ⇒ Object
Constructor Details
#initialize(name, *args) ⇒ Event
Returns a new instance of Event.
5 6 7 8 |
# File 'lib/marvin/irc/event.rb', line 5 def initialize(name, *args) self.name = name.to_sym self.keys = args.flatten.map { |k| k.to_sym } end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
3 4 5 |
# File 'lib/marvin/irc/event.rb', line 3 def keys @keys end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/marvin/irc/event.rb', line 3 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/marvin/irc/event.rb', line 3 def prefix @prefix end |
#raw_arguments ⇒ Object
Returns the value of attribute raw_arguments.
3 4 5 |
# File 'lib/marvin/irc/event.rb', line 3 def raw_arguments @raw_arguments end |
Instance Method Details
#inspect ⇒ Object
22 23 24 |
# File 'lib/marvin/irc/event.rb', line 22 def inspect "#<Marvin::IRC::Event name=#{self.name} attributes=#{self.to_hash.inspect} >" end |
#to_hash ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/marvin/irc/event.rb', line 10 def to_hash return @hash_value unless @hash_value.blank? results = {} values = self.raw_arguments.to_a last_index = self.keys.size - 1 self.keys.each_with_index do |key, i| results[key] = (i == last_index ? values.join(" ").strip : values.shift) end results.merge!(prefix.to_hash) unless prefix.blank? return (@hash_value = results) end |
#to_incoming_event_name ⇒ Object
26 27 28 |
# File 'lib/marvin/irc/event.rb', line 26 def to_incoming_event_name :"incoming_#{self.name}" end |
#to_outgoing_event_name ⇒ Object
30 31 32 |
# File 'lib/marvin/irc/event.rb', line 30 def to_outgoing_event_name :"outgoing_#{self.name}" end |