class DBF::Record
An instance of DBF::Record
represents a row in the DBF
file
Public Class Methods
Source
# File lib/dbf/record.rb, line 10 def initialize(data, columns, version, memo) @data = StringIO.new(data) @columns = columns @version = version @memo = memo end
Initialize a new DBF::Record
@param data [String, StringIO] data @param columns [Column] @param version [String] @param memo [DBF::Memo]
Public Instance Methods
Source
# File lib/dbf/record.rb, line 21 def ==(other) other.respond_to?(:attributes) && other.attributes == attributes end
Equality
@param [DBF::Record] other @return [Boolean]
Source
# File lib/dbf/record.rb, line 28 def [](name) key = name.to_s if attributes.key?(key) attributes[key] elsif (index = underscored_column_names.index(key)) attributes[@columns[index].name] end end
Reads attributes by column name
@param name [String, Symbol] key
Source
# File lib/dbf/record.rb, line 40 def attributes @attributes ||= column_names.zip(to_a).to_h end
Record
attributes
@return [Hash]
Source
# File lib/dbf/record.rb, line 48 def match?(options) options.all? { |key, value| self[key] == value } end
Do all search parameters match?
@param [Hash] options @return [Boolean]
Source
# File lib/dbf/record.rb, line 55 def to_a @to_a ||= @columns.map { |column| init_attribute(column) } end
Maps a row to an array of values
@return [Array]