Method: DBF::Table#find
- Defined in:
- lib/dbf/table.rb
#find(command, options = {}) {|optional, DBF::Record, NilClass| ... } ⇒ Object
Find 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’”.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/dbf/table.rb', line 157 def find(command, = {}, &block) case command when Integer record(command) when Array command.map { |i| record(i) } when :all find_all(, &block) when :first find_first() end end |