-
Notifications
You must be signed in to change notification settings - Fork 0
/
retweetdb.rb
49 lines (46 loc) · 1005 Bytes
/
retweetdb.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
# coding: utf-8
class RetweetDb
attr_accessor :rt
def initialize(path)
db_version = "1.0"
@rt = {}
begin
db = open(path, "r")
begin
version = db.gets.chomp
if version == db_version
num_of_record = db.gets.chomp
num_of_record.to_i.times do
id = db.gets.chomp
@rt[id] = {
id: id,
rt_count: db.gets.chomp.to_i,
rt_count_new: 0,
rt_status: db.gets.chomp.to_i
}
end
else
#version not match!
end
rescue => result
puts result
ensure
db.close
end
rescue
puts "DBリードエラー"
end
end
def save(path)
db = open(path, "w")
db.puts "1.0"
db.puts @rt.size
@rt.each do |_id, value|
#dbに書き込む
db.puts(value[:id])
db.puts(value[:rt_count_new])
db.puts(value[:rt_status])
end
db.close
end
end