Class: Bio::FlatFileIndex::BDBwrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/io/flatfile/bdb.rb

Overview

module BDBdefault

Instance Method Summary collapse

Constructor Details

#initialize(name, filename, *arg) ⇒ BDBwrapper

Returns a new instance of BDBwrapper.



44
45
46
47
48
49
# File 'lib/bio/io/flatfile/bdb.rb', line 44

def initialize(name, filename, *arg)
  @dbname = name
  @file = nil
  @filename = filename
  #self.open(*arg)
end

Instance Method Details

#[](arg) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/bio/io/flatfile/bdb.rb', line 73

def [](arg)
  #self.open
  if @file then
    @file[arg]
  else
    nil
  end
end

#[]=(key, val) ⇒ Object



82
83
84
85
# File 'lib/bio/io/flatfile/bdb.rb', line 82

def []=(key, val)
  #self.open
  @file[key.to_s] = val.to_s
end

#closeObject



64
65
66
67
68
69
70
71
# File 'lib/bio/io/flatfile/bdb.rb', line 64

def close
  if @file
    DEBUG.print "BDBwrapper: close #{filename}\n"
    @file.close
    @file = nil
  end
  nil
end

#filenameObject



51
52
53
# File 'lib/bio/io/flatfile/bdb.rb', line 51

def filename
  File.join(@dbname, @filename)
end

#keysObject



95
96
97
98
99
100
101
# File 'lib/bio/io/flatfile/bdb.rb', line 95

def keys
  if @file then
    @file.keys
  else
    []
  end
end

#open(flag = BDBdefault.flag_read, permission = BDBdefault.permission) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/bio/io/flatfile/bdb.rb', line 55

def open(flag = BDBdefault.flag_read,
         permission = BDBdefault.permission)
  unless @file then
    DEBUG.print "BDBwrapper: open #{filename}\n"
    @file = BDB::Btree.open(filename, nil, flag, permission)
  end
  true
end

#writeback_array(prefix, array, *arg) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/bio/io/flatfile/bdb.rb', line 87

def writeback_array(prefix, array, *arg)
  self.close
  self.open(*arg)
  array.each_with_index do |val, key|
    @file["#{prefix}#{key}"] = val.to_s
  end
end