class DBF::Database::Foxpro
Public Class Methods
new(path)
click to toggle source
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]
# 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
Public Instance Methods
respond_to_missing?(method, *)
click to toggle source
Calls superclass method
# File lib/dbf/database/foxpro.rb, line 62 def respond_to_missing?(method, *) table_names.index(method.to_s) || super end
table(name)
click to toggle source
Returns table with given name
@param name [String] @return [DBF::Table]
# 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
table_names()
click to toggle source
# File lib/dbf/database/foxpro.rb, line 30 def table_names @tables.keys end
table_path(name)
click to toggle source
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]
# 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
Private Instance Methods
process_field(record, data)
click to toggle source
# File lib/dbf/database/foxpro.rb, line 99 def process_field(record, data) id = record.parentid name = 'UNKNOWN' field = record.objectname data[id] ||= table_field_hash(name) data[id][:fields] << field end
process_table(record, data)
click to toggle source
# File lib/dbf/database/foxpro.rb, line 93 def process_table(record, data) id = record.objectid name = record.objectname data[id] = table_field_hash(name) end
table_field_hash(name)
click to toggle source
# File lib/dbf/database/foxpro.rb, line 107 def table_field_hash(name) {name: name, fields: []} end