-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.rb~
39 lines (37 loc) · 892 Bytes
/
news.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
f = open("news.js")
list = Array.new
mode = 0
date = "\\d+\\/\\d+\\/\\d+"
id1 = 0
id2 = 0
f.each do |line|
if mode == 0
if /^\[$/.match(line)
mode = 1
puts "mode move into 1"
end
elsif mode == 1
if /NEWS_DETAIL/.match(line)
mode = 2
puts "mode move into 2"
elsif tmp = /\["(?<date>#{date}).*"\s*,\s*"(?<kind>[0|1|2])"\s*,\s*"(?<title>.*)"\]/.match(line)
puts "#{tmp[:date]} #{tmp[:kind]} #{tmp[:title]}"
list[id1]=News.new(date:tmp[:date], kind:tmp[:kind], title:tmp[:title])
end
elsif mode == 2
if /^\];/.match(line)
mode = 3
elsif tmp = /"(?<detail>.*)",?$/.match(line)
tmp.[:detail].gsub!(/\\\"/, "\"")
puts tmp[:detail]
list[id2].update(detail:tmp[:detail])
end
elsif mode == 3
if id1 != id2
puts "hey, it seems wrong!"
end
end
end
list.each do |news|
puts news
end