class InfoDB

Attributes

db[RW]
file_path[RW]
text_dir[RW]

Public Class Methods

new(file_path) click to toggle source
# File lib/hikiutils/infodb.rb, line 6
  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

Public Instance Methods

delete(name) click to toggle source
# File lib/hikiutils/infodb.rb, line 32
def delete(name)
  p @db.delete(name)
end
dump() click to toggle source
# File lib/hikiutils/infodb.rb, line 45
def dump
  dump_file = File.open(@file_path,'w')
  TMarshal::dump(@db,dump_file)
  dump_file.close
end
show(name) click to toggle source
# File lib/hikiutils/infodb.rb, line 28
def show(name)
  @db[name]
end
show_inconsist() click to toggle source
# File lib/hikiutils/infodb.rb, line 51
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
update(name) click to toggle source
# File lib/hikiutils/infodb.rb, line 36
def update(name)
  if @db[name]==nil then
    puts "no info"
    exit
  end
  p @db[name][:last_modified] = Time.now
  self.dump
end