Module: Persist::FWTAdapter

Includes:
TSVAdapter
Defined in:
lib/rbbt/persist/tsv/fix_width_table.rb

Constant Summary

Constants included from TSVAdapter

TSVAdapter::MAX_CHAR

Instance Attribute Summary collapse

Attributes included from TSVAdapter

#closed, #mutex, #persistence_path, #writable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TSVAdapter

#close, #closed?, #collect, #delete, #get_prefix, #lock, #lock_and_close, #merge!, #prefix, #range, #read, #read?, #read_and_close, #read_lock, #values_at, #with_read, #with_write, #write, #write?, #write_and_close, #write_and_read, #write_lock

Instance Attribute Details

#pos_functionObject

Returns the value of attribute pos_function.



8
9
10
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 8

def pos_function
  @pos_function
end

Class Method Details

.open(path, value_size, range = false, update = false, in_memory = false, &pos_function) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 10

def self.open(path, value_size, range = false, update = false, in_memory = false, &pos_function)
  db = CONNECTIONS[path] ||= FixWidthTable.new(path, value_size, range, update, in_memory)
  db.extend Persist::FWTAdapter
  db.persistence_path = path
  db.pos_function = pos_function
  db
end

Instance Method Details

#<<(key, value) ⇒ Object



73
74
75
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 73

def <<(key, value)
  self.send(:[]=, *i)
end

#[](key) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 40

def [](key)
  if TSV::ENTRY_KEYS.include? key
    [key]
  else
    key = pos_function.call(key) if pos_function
    res = super(key)
    res.extend MultipleResult
    res
  end
end

#[]=(key, value) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 51

def []=(key, value)
  if TSV::ENTRY_KEYS.include? key
    (key, value)
  else
    if @range
      add_range_point key, value
    else
      add key, value
    end
  end
end

#add(key, value) ⇒ Object



63
64
65
66
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 63

def add(key, value)
  key = pos_function.call(key) if pos_function and not (@range and Array === key)
  super(key, value)
end

#add_range_point(key, value) ⇒ Object



68
69
70
71
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 68

def add_range_point(key, value)
  key = pos_function.call(key) if pos_function
  super(key, value)
end

#eachObject



87
88
89
90
91
92
93
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 87

def each
  read
  @size.times do |i|
    v = idx_value(i)
    yield i, v
  end
end

#include?(i) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 77

def include?(i)
  return true if Numeric === i and i < pos(@size)
  return true if .include? i
  false
end

#keysObject



95
96
97
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 95

def keys
  []
end

#metadataObject



27
28
29
30
31
32
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 27

def 
  return {} unless File.exist? 
  Open.open(, :mode => "rb") do |f|
    Marshal.load(f)
  end
end

#metadata_fileObject



23
24
25
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 23

def 
  @metadata_file ||= self.persistence_path + '.metadata'
end

#persistence_path=(value) ⇒ Object



18
19
20
21
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 18

def persistence_path=(value)
  @persistence_path = value
  @filename = value
end

#set_metadata(k, v) ⇒ Object



34
35
36
37
38
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 34

def (k,v)
   = self.
  [k] = v
  Misc.sensiblewrite(, Marshal.dump())
end

#sizeObject



83
84
85
# File 'lib/rbbt/persist/tsv/fix_width_table.rb', line 83

def size
  @size
end