Class: Bio::FlatFileIndex::BDBwrapper
- Defined in:
- lib/bio/io/flatfile/bdb.rb
Overview
module BDBdefault
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #[]=(key, val) ⇒ Object
- #close ⇒ Object
- #filename ⇒ Object
-
#initialize(name, filename, *arg) ⇒ BDBwrapper
constructor
A new instance of BDBwrapper.
- #keys ⇒ Object
- #open(flag = BDBdefault.flag_read, permission = BDBdefault.permission) ⇒ Object
- #writeback_array(prefix, array, *arg) ⇒ Object
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 |
#close ⇒ Object
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 |
#filename ⇒ Object
51 52 53 |
# File 'lib/bio/io/flatfile/bdb.rb', line 51 def filename File.join(@dbname, @filename) end |
#keys ⇒ Object
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, = BDBdefault.) unless @file then DEBUG.print "BDBwrapper: open #{filename}\n" @file = BDB::Btree.open(filename, nil, flag, ) 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 |