Class: MessageFactory::Handlers::Names

Inherits:
Handler
  • Object
show all
Defined in:
lib/handlers/Names.rb

Instance Method Summary collapse

Constructor Details

#initializeNames

Returns a new instance of Names.



10
11
12
# File 'lib/handlers/Names.rb', line 10

def initialize
    @cache = {}
end

Instance Method Details

#end_names(string, orig) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/handlers/Names.rb', line 68

def end_names(string, orig)
    string.slice!(0)
    string.slice!(0, string.index(' ')+1)
    channel = string.slice!(0, string.index(' '))
    m = nil
    if(@cache[channel])
        m = @cache[channel]
        m.raw.push(orig)
        @cache.delete(channel)
    end
    m
end

#names(string, orig) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/handlers/Names.rb', line 47

def names(string, orig)
    string.slice!(0)
    target = string.slice!(0, string.index(' '))
    string.slice!(0, 3)
    channel = string.slice!(0, string.index(' '))
    m = @cache[channel] ? @cache[channel] : mk_struct(orig)
    m.type = :names
    m.target = target
    m.channel = channel
    if(m.raw.is_a?(Array))
        m.raw.push(orig)
    else
        m.raw = [m.raw]
    end
    string.slice!(0, string.index(':')+1)
    m.nicks ||= []
    m.nicks = m.nicks + string.split
    @cache[channel] = m
    nil
end

#process(string) ⇒ Object

string

string to process

Create a new Names message OpenStruct will contain: #type #direction #raw #received #target #channel #server #nicks :nodoc: :swiftco.wa.us.dal.net 353 spox = #mod_spox :mod_spox spox :nodoc: :swiftco.wa.us.dal.net 366 spox #mod_spox :End of /NAMES list.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/handlers/Names.rb', line 22

def process(string)
    string = string.dup
    orig = string.dup
    m = nil
    begin
        string.slice!(0)
        server = string.slice!(0, string.index(' '))
        string.slice!(0)
        case string.slice!(0, string.index(' ')).to_sym
        when :'353'
            m = names(string, orig)
        when :'366'
            m = end_names(string, orig)
        else
            raise 'error'
        end
        if(m)
            m.server = server
        end
    rescue
        raise "Failed to parse Name message: #{orig}"
    end
    m
end

#types_processObject



13
14
15
# File 'lib/handlers/Names.rb', line 13

def types_process
    [:'353', :'366']
end