Sha256: 82effe1488f0a6b880e626fb73864596550252a5bd3487df00e19eb35d2b4bff

Contents?: true

Size: 899 Bytes

Versions: 12

Compression:

Stored size: 899 Bytes

Contents

module Marvin::IRC
  class Event
    attr_accessor :keys, :name, :raw_arguments, :prefix
    
    def initialize(name, *args)
      self.name = name.to_sym
      self.keys = args.flatten.map { |k| k.to_sym }
    end
    
    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
    
    def inspect
      "#<Marvin::IRC::Event name=#{self.name} attributes=#{self.to_hash.inspect} >"
    end
    
    def to_incoming_event_name
      :"incoming_#{self.name}"
    end
    
    def to_outgoing_event_name
      :"outgoing_#{self.name}"
    end
    
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
Sutto-marvin-0.1.20081120 lib/marvin/irc/event.rb
Sutto-marvin-0.2.0 lib/marvin/irc/event.rb
Sutto-marvin-0.2.1 lib/marvin/irc/event.rb
Sutto-marvin-0.2.2 lib/marvin/irc/event.rb
Sutto-marvin-0.2.3 lib/marvin/irc/event.rb
Sutto-marvin-0.2.4 lib/marvin/irc/event.rb
Sutto-marvin-0.3.0 lib/marvin/irc/event.rb
Sutto-marvin-0.3.2 lib/marvin/irc/event.rb
Sutto-marvin-0.3.3 lib/marvin/irc/event.rb
Sutto-marvin-0.3.4 lib/marvin/irc/event.rb
Sutto-marvin-0.4.0 lib/marvin/irc/event.rb
jeffrafter-marvin-0.1.20081120 lib/marvin/irc/event.rb