Sha256: 649c5048c7a0c795f4d718332f94a23635415398d2282adfbe39402ac05829a8

Contents?: true

Size: 1.41 KB

Versions: 21

Compression:

Stored size: 1.41 KB

Contents

# -*- coding: utf-8 -*-
require 'nkf'
require 'kconv'

class InfoDB
  attr_accessor :file_path, :db, :text_dir
  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

  def show_link(file_name)
    @db.each{|ele|
      ref = ele[1][:references]
      if ref.include?(file_name) then
        p ele[0]
      end
    }
  end

  def show(name)
    @db[name]
  end

  def delete(name)
    p @db.delete(name)
  end

  def update(name)
    if @db[name]==nil then
      puts "no info"
      exit
    end
    p @db[name][:last_modified] = Time.now
    self.dump
  end

  def dump
    dump_file = File.open(@file_path,'w')
    TMarshal::dump(@db,dump_file)
    dump_file.close
  end

  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
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hikiutils-0.2.4 lib/hikiutils/infodb.rb
hikiutils-0.2.3.17 lib/hikiutils/infodb.rb
hikiutils-0.2.3.16 lib/hikiutils/infodb.rb
hikiutils-0.2.3.15 lib/hikiutils/infodb.rb
hikiutils-0.2.3.14 lib/hikiutils/infodb.rb
hikiutils-0.2.3.13 lib/hikiutils/infodb.rb
hikiutils-0.2.3.12 lib/hikiutils/infodb.rb
hikiutils-0.2.3.11 lib/hikiutils/infodb.rb
hikiutils-0.2.3.9 lib/hikiutils/infodb.rb
hikiutils-0.2.3.8 lib/hikiutils/infodb.rb
hikiutils-0.2.3.7 lib/hikiutils/infodb.rb
hikiutils-0.2.3.6 lib/hikiutils/infodb.rb
hikiutils-0.2.3.4 lib/hikiutils/infodb.rb
hikiutils-0.2.3.3 lib/hikiutils/infodb.rb
hikiutils-0.2.3.2 lib/hikiutils/infodb.rb
hikiutils-0.2.3.1 lib/hikiutils/infodb.rb
hikiutils-0.2.3 lib/hikiutils/infodb.rb
hikiutils-0.2.2 lib/hikiutils/infodb.rb
hikiutils-0.2.1 lib/hikiutils/infodb.rb
hikiutils-0.2.0 lib/hikiutils/infodb.rb