Class: LogHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/log_helper.rb

Constant Summary collapse

@@ids =
{
    'D' => 0, 
    'M' => 1,
    'S' => 2,
    'F' => 3,
    'T' => 4,
    'C' => 5
}

Instance Method Summary collapse

Constructor Details

#initialize(groups) ⇒ LogHelper

Returns a new instance of LogHelper.



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

def initialize(groups)
    @groups = groups
end

Instance Method Details

#concatattach(group) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/log_helper.rb', line 56

def concatattach(group)
    v = concatval(group)

    pstart = v.index('filename=')
    return '' unless pstart
    pstart += 9

    pend = v.length - 1
    return '' unless pend >= pstart
    if v[pstart] == '"'
        quote2nd = v.rindex('"')
        if quote2nd and quote2nd > pstart
            pstart += 1
            pend = quote2nd - 1
        end
    end

    v[pstart..pend]
end

#concatval(group) ⇒ Object



76
77
78
79
80
81
# File 'lib/log_helper.rb', line 76

def concatval(group)
    return group[:value] unless group[:afterlines]

    al = group[:afterlines].join("\a")
    "#{group[:value]}\a#{al}"
end

#isvalend?(group) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/log_helper.rb', line 50

def isvalend?(group)
    return true unless group[:afterlines]
    return false unless group[:valend]
    true
end

#others_complete?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/log_helper.rb', line 21

def others_complete?
    @valends[0] && @valends[1] && @valends[2] && @valends[3] && @valends[6]
end

#tocc_complete?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/log_helper.rb', line 17

def tocc_complete?
    @valends[4] && @valends[5]
end

#tocolsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/log_helper.rb', line 25

def tocols
    @valends = Array.new(7, true)
    cols = Array.new(6)

    @groups.each do |g|
        key = g[:key]
        next unless key and key.length > 1 

        cap = key[0].upcase
        next unless @@ids.has_key?(cap)

        if cap == 'C' and key[1].downcase == 'o'
            cols << concatattach(g)
            @valends[-1] &= isvalend?(g)
        else
            id = @@ids[cap]
            next if cols[id]
            cols[id] = concatval(g)
            @valends[id] = isvalend?(g)
        end
    end

    cols
end