class CsvRecord::Query
Attributes
conditions[R]
klass[R]
Public Class Methods
new(klass, conditions)
click to toggle source
# File lib/csv_record/query.rb, line 10 def initialize(klass, conditions) @klass = klass @conditions = conditions.map do |condition| CsvRecord::Condition.new(*condition) end end
Public Instance Methods
__to_a__()
click to toggle source
# File lib/csv_record/query.rb, line 35 def __to_a__ trigger end
Also aliased as: to_a
__trigger__()
click to toggle source
# File lib/csv_record/query.rb, line 24 def __trigger__ klass.open_database_file do |csv| rows = search_for csv, conditions rows.map { |row| klass.build row.to_hash } end end
Also aliased as: trigger
__where__(params)
click to toggle source
# File lib/csv_record/query.rb, line 18 def __where__(params) new_conditions = (CsvRecord::Condition.create_from_hashes params) @conditions = (@conditions << new_conditions).flatten # figure out a way to solve this later self end
Also aliased as: where
each(&block)
click to toggle source
# File lib/csv_record/query.rb, line 43 def each(&block) to_a.each(&block) end
empty?()
click to toggle source
# File lib/csv_record/query.rb, line 47 def empty? to_a.empty? end
inspect()
click to toggle source
# File lib/csv_record/query.rb, line 31 def inspect to_a.inspect end
last()
click to toggle source
# File lib/csv_record/query.rb, line 39 def last to_a.last end
Private Instance Methods
conditions_as_string()
click to toggle source
# File lib/csv_record/query.rb, line 63 def conditions_as_string @_conditions_as_string ||= conditions.map(&:to_code).join ' and ' end
search_for(csv, params)
click to toggle source
# File lib/csv_record/query.rb, line 57 def search_for(csv, params) csv.entries.select do |attributes| eval conditions_as_string end end