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