/
data_processor.rb
63 lines (50 loc) · 1.54 KB
/
data_processor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'pathname'
class DataProcessor
def initialize(authorList)
@tpl="view/default.tpl.html"
@authorList = authorList
end
def self.loadAuthorList(authorList)
DataProcessor.new(authorList)
end
def installTpl(tpl)
@tpl=tpl
self
end
def render()
end
def rank
end
def out2Html(title)
tplFile = open @tpl
tplContent = tplFile.read
tplFile.close
content =""
for i in 0 .. @authorList.length-1
author = @authorList[i]
content+=format(" <tr>
<td>%s</td>
<td><a target= \"_blank\" href=\"http://jianshu.com/users/%s\">%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>", i, author.id, author.name, author.post_count, author.word_count, author.read_count, author.comment_count, author.liked_count, author.fans_count,author.buddy)
end
today = Time.new;
timeStr= today.strftime("(%Y-%m-%d %H:%M:%S)");
footer="Powered By <a target=\"_blank\" href=\"http://wangbaiyuan.cn\">BrainWang@ThoughtWorks</a>"
out = tplContent.gsub(/@\{title\}/, title)
out = out.gsub(/@\{content\}/, content)
out = out.gsub(/@\{footer\}/, footer)
out = out.gsub(/@\{time\}/, timeStr)
timeStr= today.strftime("(%Y-%m-%d)");
file=open("output/#{title+timeStr}.html", "w")
file.write out
print "\n输出文件位于", Pathname.new(File.dirname(__FILE__)).realpath, "/", file.path, "\n"
file.close
end
end