class DBF::Database::Foxpro
Public Class Methods
Source
# File lib/dbf/database/foxpro.rb, line 21 def initialize(path) @path = path @dirname = File.dirname(@path) @db = DBF::Table.new(@path) @tables = extract_dbc_data rescue Errno::ENOENT raise DBF::FileNotFoundError, "file not found: #{data}" end
Opens a DBF::Database::Foxpro
Examples:
# working with a database stored on the filesystem db = DBF::Database::Foxpro.new 'path_to_db/database.dbc' # Calling a table contacts = db.contacts.record(0)
@param path [String]
Public Instance Methods
Source
# File lib/dbf/database/foxpro.rb, line 62 def respond_to_missing?(method, *) table_names.index(method.to_s) || super end
Calls superclass method
Source
# File lib/dbf/database/foxpro.rb, line 38 def table(name) Table.new table_path(name) do |table| table.long_names = @tables[name] end end
Returns table with given name
@param name [String] @return [DBF::Table]
Source
# File lib/dbf/database/foxpro.rb, line 49 def table_path(name) glob = File.join(@dirname, "#{name}.dbf") path = Dir.glob(glob, File::FNM_CASEFOLD).first raise DBF::FileNotFoundError, "related table not found: #{name}" unless path && File.exist?(path) path end
Searches the database directory for the table’s dbf file and returns the absolute path. Ensures case-insensitivity on any platform. @param name [String] @return [String]
Private Instance Methods
Source
# File lib/dbf/database/foxpro.rb, line 97 def process_field(record, data) id = record.parentid name = 'UNKNOWN' field = record.objectname data[id] ||= table_field_hash(name) data[id][:fields] << field end
Source
# File lib/dbf/database/foxpro.rb, line 91 def process_table(record, data) id = record.objectid name = record.objectname data[id] = table_field_hash(name) end
Source
# File lib/dbf/database/foxpro.rb, line 105 def table_field_hash(name) {name: name, fields: []} end