Class: ADT::Table

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Rails, Schema
Defined in:
lib/adt/table.rb

Overview

ADT::Table is the primary interface to a single ADT file and provides methods for enumerating and searching the records.

Constant Summary collapse

ADT_HEADER_SIZE =
400

Constants included from Schema

Schema::FORMATS, Schema::OTHER_DATA_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rails

#model

Methods included from Schema

#activerecord_schema, #activerecord_schema_definition, #json_schema, #schema, #schema_data_type, #schema_name, #string_data_format

Constructor Details

#initialize(data) {|_self| ... } ⇒ Table

Opens a ADT::Table Examples:

# working with a file stored on the filesystem
table = ADT::Table.new 'data.adt'

Parameters:

  • data (String)

    Path to the adt file

Yields:

  • (_self)

Yield Parameters:

  • _self (ADT::Table)

    the object that the method was called on



27
28
29
30
31
# File 'lib/adt/table.rb', line 27

def initialize(data)
  @data = open_data(data)
  @memory = open_data(data.gsub('.adt', '.adm')) if File.exist?(data.gsub('.adt', '.adm'))
  yield self if block_given?
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



92
93
94
# File 'lib/adt/table.rb', line 92

def data
  @data
end

#memoryObject (readonly)

Returns the value of attribute memory.



19
20
21
# File 'lib/adt/table.rb', line 19

def memory
  @memory
end

Instance Method Details

#closeTrueClass, FalseClass

Closes the table

Returns:

  • (TrueClass, FalseClass)


36
37
38
# File 'lib/adt/table.rb', line 36

def close
  @data.close
end

#closed?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


46
47
48
# File 'lib/adt/table.rb', line 46

def closed?
  @data.closed?
end

#column_namesString

Column names

Returns:

  • (String)


81
82
83
# File 'lib/adt/table.rb', line 81

def column_names
  columns.map(&:underscored_name)
end

#columnsArray

All columns

Returns:

  • (Array)


74
75
76
# File 'lib/adt/table.rb', line 74

def columns
  @columns ||= build_columns
end

#each {|nil, ADT::Record| ... } ⇒ Object

Calls block once for each record in the table. The record may be nil if the record has been marked as deleted.

Yields:



54
55
56
# File 'lib/adt/table.rb', line 54

def each
  record_count.times { |i| yield record(i) }
end

#filenameString

Returns:

  • (String)


86
87
88
89
90
# File 'lib/adt/table.rb', line 86

def filename
  return unless @data.respond_to?(:path)

  File.basename(@data.path)
end

#memory?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


41
42
43
# File 'lib/adt/table.rb', line 41

def memory?
  !@memory.nil?
end

#nameObject



94
95
96
# File 'lib/adt/table.rb', line 94

def name
  filename.gsub('.adt', '')
end

#record(index) ⇒ ADT::Record, NilClass

Retrieve a record by index number. The record will be nil if it has been deleted, but not yet pruned from the database.

Parameters:

  • index (Integer)

Returns:



64
65
66
67
68
69
# File 'lib/adt/table.rb', line 64

def record(index)
  seek_to_record(index)
  return nil if deleted_record?

  ADT::Record.new(@data.read(record_length), columns, self)
end