Class: Marvin::IRC::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/marvin/irc/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keysObject

Returns the value of attribute keys.



3
4
5
# File 'lib/marvin/irc/event.rb', line 3

def keys
  @keys
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/marvin/irc/event.rb', line 3

def name
  @name
end

#prefixObject

Returns the value of attribute prefix.



3
4
5
# File 'lib/marvin/irc/event.rb', line 3

def prefix
  @prefix
end

#raw_argumentsObject

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

#inspectObject



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_hashObject



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_nameObject



30
31
32
# File 'lib/marvin/irc/event.rb', line 30

def to_incoming_event_name
  to_event_name :incoming
end

#to_outgoing_event_nameObject



34
35
36
# File 'lib/marvin/irc/event.rb', line 34

def to_outgoing_event_name
  to_event_name :outgoing
end