Class: InfoDB
- Inherits:
-
Object
- Object
- InfoDB
- Defined in:
- lib/hikiutils/infodb.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#text_dir ⇒ Object
Returns the value of attribute text_dir.
Instance Method Summary collapse
- #delete(name) ⇒ Object
- #dump ⇒ Object
-
#initialize(file_path) ⇒ InfoDB
constructor
A new instance of InfoDB.
- #show(name) ⇒ Object
- #show_inconsist ⇒ Object
- #show_link(file_name) ⇒ Object
- #update(name) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ InfoDB
Returns a new instance of InfoDB.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hikiutils/infodb.rb', line 7 def initialize(file_path) @file_path=File.join(file_path,"info.db") @db = Hash.new file = File.read(@file_path) # if Kconv.iseuc(file) then # fail to guess if NKF.guess(file)==NKF::EUC then print "WARNING : this info.db is written in euc, thus not supported.\n" print "#{@file_path}.\n" exit end @db = TMarshal::load(file) end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
6 7 8 |
# File 'lib/hikiutils/infodb.rb', line 6 def db @db end |
#file_path ⇒ Object
Returns the value of attribute file_path.
6 7 8 |
# File 'lib/hikiutils/infodb.rb', line 6 def file_path @file_path end |
#text_dir ⇒ Object
Returns the value of attribute text_dir.
6 7 8 |
# File 'lib/hikiutils/infodb.rb', line 6 def text_dir @text_dir end |
Instance Method Details
#delete(name) ⇒ Object
33 34 35 |
# File 'lib/hikiutils/infodb.rb', line 33 def delete(name) p @db.delete(name) end |
#dump ⇒ Object
46 47 48 49 50 |
# File 'lib/hikiutils/infodb.rb', line 46 def dump dump_file = File.open(@file_path,'w') TMarshal::dump(@db,dump_file) dump_file.close end |
#show(name) ⇒ Object
29 30 31 |
# File 'lib/hikiutils/infodb.rb', line 29 def show(name) @db[name] end |
#show_inconsist ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hikiutils/infodb.rb', line 52 def show_inconsist @text_dir = Dir::entries(File.join(file_path,"text"))[3..-1] cont = "" @text_dir.each { |ent| if @db[ent]==nil then cont << "in text_dir but not in db:#{ent}\n" next end # newdb.store(ent,db[ent]) } @db.each { |ent| name = ent[0] if !(@text_dir.member? (name)) then cont << "in db but not in text_dir:#{name}\n" end } return cont end |
#show_link(file_name) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/hikiutils/infodb.rb', line 20 def show_link(file_name) @db.each{|ele| ref = ele[1][:references] if ref.include?(file_name) then p ele[0] end } end |
#update(name) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/hikiutils/infodb.rb', line 37 def update(name) if @db[name]==nil then puts "no info" exit end p @db[name][:last_modified] = Time.now self.dump end |