Class: ADT::Table
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
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
Instance Method Summary collapse
-
#close ⇒ TrueClass, FalseClass
Closes the table.
- #closed? ⇒ TrueClass, FalseClass
-
#column_names ⇒ String
Column names.
-
#columns ⇒ Array
All columns.
-
#each {|nil, ADT::Record| ... } ⇒ Object
Calls block once for each record in the table.
- #filename ⇒ String
-
#initialize(data) {|_self| ... } ⇒ Table
constructor
Opens a ADT::Table Examples: # working with a file stored on the filesystem table = ADT::Table.new ‘data.adt’.
- #memory? ⇒ TrueClass, FalseClass
- #name ⇒ Object
-
#record(index) ⇒ ADT::Record, NilClass
Retrieve a record by index number.
Methods included from Rails
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'
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
92 93 94 |
# File 'lib/adt/table.rb', line 92 def data @data end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
19 20 21 |
# File 'lib/adt/table.rb', line 19 def memory @memory end |
Instance Method Details
#close ⇒ TrueClass, FalseClass
Closes the table
36 37 38 |
# File 'lib/adt/table.rb', line 36 def close @data.close end |
#closed? ⇒ TrueClass, FalseClass
46 47 48 |
# File 'lib/adt/table.rb', line 46 def closed? @data.closed? end |
#column_names ⇒ String
Column names
81 82 83 |
# File 'lib/adt/table.rb', line 81 def column_names columns.map(&:underscored_name) end |
#columns ⇒ Array
All columns
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.
54 55 56 |
# File 'lib/adt/table.rb', line 54 def each record_count.times { |i| yield record(i) } end |
#filename ⇒ 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
41 42 43 |
# File 'lib/adt/table.rb', line 41 def memory? !@memory.nil? end |
#name ⇒ Object
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.
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 |