Class: ToCcParser

Inherits:
BaseParser show all
Defined in:
lib/to_cc_parser.rb

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize, #isduplicate, #parse, #parsegrep, #shouldabsent, #shouldexist

Constructor Details

This class inherits a constructor from BaseParser

Instance Method Details

#convert(curfile, lines) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/to_cc_parser.rb', line 60

def convert(curfile, lines)
    return unless lines and lines.length > 0

    gm = GrepMail.new(curfile, lines, 300)
    cols = gm.tocols
#no need to check duplicate here, cause no COPY_ file in mlog
#output tocc or others mails anyway, better than disk overflow.
    key = File.basename(curfile)
    @toccs[key] = cols unless @toccs.has_key?(key)

    @tocc2count += 1 if gm.istocc?
end

#formatcount(part, total) ⇒ Object



43
44
45
# File 'lib/to_cc_parser.rb', line 43

def formatcount(part, total)
    "#{part}(#{total == 0 ? '-' : part * 100 / total}%) row#{part > 1 ? 's' : ''}"
end

#parse_with_summaryObject



8
9
10
11
12
13
14
# File 'lib/to_cc_parser.rb', line 8

def parse_with_summary
    grep, mtocc = shouldexist('.grep.tocc', '.mtocc')
    
    @tocc2count = 0
    parsetocc grep
    replace_tocc mtocc
end

#parsetocc(grep) ⇒ Object



55
56
57
58
# File 'lib/to_cc_parser.rb', line 55

def parsetocc(grep)
    @toccs = {}
    parsegrep grep
end

#replace_tocc(mtocc) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/to_cc_parser.rb', line 16

def replace_tocc(mtocc)
    inputcount = 0
    replacecount = 0 
    mlog = @oh.getmout('.mlog')
    File.open(mlog, 'a') do |omlog|
        File.foreach(mtocc) do |line|
            inputcount += 1
            cols = splitmlog(line)
            next unless cols

            fn = cols[0]
            if @toccs.has_key?(fn)
                replacecount += 1
                tocc = @toccs[fn]
                cols[4+1] = tocc[4]
                cols[5+1] = tocc[5]
                omlog.puts cols[1..-1].join("\t")
            end
        end
    end

    msg = "#{formatcount(replacecount, inputcount)} replaced "
    msg << "(include #{formatcount(@tocc2count, inputcount)} tocc cut). "
    msg << "#{formatcount(inputcount - replacecount, inputcount)} ignored. "
    msg << "Totally #{inputcount} row#{inputcount > 1 ? 's' : ''} from .mtocc file."
end

#splitmlog(linehasn, colcount = 7) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/to_cc_parser.rb', line 47

def splitmlog(linehasn, colcount = 7)
    return nil unless linehasn and linehasn.length >= colcount
    cols = linehasn.split("\t")
    return nil if cols.length < colcount
    cols[-1] = cols[-1][0..-2]
    cols
end