Class: OutputHelper

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

Instance Method Summary collapse

Constructor Details

#initialize(output, timestamp) ⇒ OutputHelper

Returns a new instance of OutputHelper.



4
5
6
7
8
9
10
11
12
# File 'lib/output_helper.rb', line 4

def initialize(output, timestamp)
    @output = output
    @timestamp = timestamp

    @mlogcount = 0
    @duplicount = 0
    @tocccount = 0
    @otherscount = 0
end

Instance Method Details

#countmsg(count, total) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/output_helper.rb', line 49

def countmsg(count, total)
    if total == 0
        "#{count}(-%)"
    else
        "#{count}(#{count * 100 / total}%)"
    end
end

#finishoutputObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/output_helper.rb', line 29

def finishoutput
    @omlog.close if @omlog
    @ofok.close if @ofok

    @omlogtocc.close if @omlogtocc
    @oftocc.close if @oftocc

    @ofothers.close if @ofothers

    getsummary
end

#getdir(prefix) ⇒ Object



24
25
26
27
# File 'lib/output_helper.rb', line 24

def getdir(prefix)
    dirname = "#{prefix}#{@timestamp}"
    File.join(@output, dirname)
end

#getfile(line) ⇒ Object



14
15
16
17
18
# File 'lib/output_helper.rb', line 14

def getfile(line)
    pos = line.index(':')
    return nil unless pos
    line[0..(pos-1)]
end

#getmout(ext) ⇒ Object



20
21
22
# File 'lib/output_helper.rb', line 20

def getmout(ext)
    File.join(@output, "mout#{@timestamp}#{ext}")
end

#getsummaryObject



41
42
43
44
45
46
47
# File 'lib/output_helper.rb', line 41

def getsummary
    totalcount = @mlogcount + @duplicount + @tocccount + @otherscount
    summary = "#{totalcount} mails processsed. log = #{countmsg(@mlogcount, totalcount)}"
    summary << "\n  duplicate = #{countmsg(@duplicount, totalcount)}"
    summary << ", tocc = #{countmsg(@tocccount, totalcount)}"
    summary << ", others = #{countmsg(@otherscount, totalcount)}"
end

#outputmlog(mailpath, line) ⇒ Object



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

def outputmlog(mailpath, line)
    unless @omlog
        mlog = getmout('.mlog')
        @omlog = File.open(mlog, 'w') 
        fok = getmout('.fok')
        @ofok = File.open(fok, 'w') 
    end
    if line
        @omlog.puts line
        @mlogcount += 1
        @ofok.puts mailpath
    else
        @duplicount += 1
        @ofok.write '#'
        @ofok.puts mailpath
    end
end

#outputmlog_from_others(line) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/output_helper.rb', line 98

def outputmlog_from_others(line)
    unless @omlog
        mlog = getmout('.mlog')
        @omlog = File.open(mlog, 'a') 
    end
    if line
        @omlog.puts line
        @mlogcount += 1
    else
        @duplicount += 1
    end
end

#outputothers(mailpath) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/output_helper.rb', line 88

def outputothers(mailpath)
    unless @ofothers
        fothers = getmout('.fothers')
        @ofothers = File.open(fothers, 'w') 
    end

    @ofothers.puts mailpath
    @otherscount += 1
end

#outputtocc(mailpath, line) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/output_helper.rb', line 75

def outputtocc(mailpath, line)
    unless @oftocc
        ftocc = getmout('.ftocc')
        @oftocc = File.open(ftocc, 'w') 
        mlogtocc = getmout('.mtocc')
        @omlogtocc = File.open(mlogtocc, 'w') 
    end

    @omlogtocc.puts "#{File.basename(mailpath)}\t#{line}"
    @oftocc.puts mailpath
    @tocccount += 1
end