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_event_name(prefix = nil) ⇒ 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) @name = name.to_sym @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=#{@name} attributes=#{to_hash.inspect} >" end |
#to_event_name(prefix = nil) ⇒ Object
26 27 28 |
# File 'lib/marvin/irc/event.rb', line 26 def to_event_name(prefix = nil) [prefix, @name].join("_").to_sym 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 = @raw_arguments.to_a last_index = @keys.size - 1 @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? @hash_value = results end |
#to_incoming_event_name ⇒ Object
30 31 32 |
# File 'lib/marvin/irc/event.rb', line 30 def to_incoming_event_name to_event_name :incoming end |
#to_outgoing_event_name ⇒ Object
34 35 36 |
# File 'lib/marvin/irc/event.rb', line 34 def to_outgoing_event_name to_event_name :outgoing end |