Module: DBF::Find
- Included in:
- Table
- Defined in:
- lib/dbf/find.rb
Overview
The Find module provides methods for searching and retrieving records using a simple ActiveRecord-like syntax.
Examples:
table = DBF::Table.new 'mydata.dbf'
# Find record number 5
table.find(5)
# Find all records for Keith Morrison
table.find :all, first_name: "Keith", last_name: "Morrison"
# Find first record
table.find :first, first_name: "Keith"
The command may be a record index, :all, or :first. options is optional and, if specified, should be a hash where the keys correspond to column names in the database. The values will be matched exactly with the value in the database. If you specify more than one key, all values must match in order for the record to be returned. The equivalent SQL would be "WHERE key1 = 'value1' AND key2 = 'value2'".
Instance Method Summary collapse
Instance Method Details
#find(command, options = {}) {|optional, DBF::Record, NilClass| ... } ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/dbf/find.rb', line 30 def find(command, = {}, &) case command when Integer then record(command) when Array then command.map { |index| record(index) } when :all then find_all_records(, &) when :first then find_first_record() end end |