lib/csv/table/table.rb in smart_csv-0.0.7 vs lib/csv/table/table.rb in smart_csv-0.0.9
- old
+ new
@@ -3,21 +3,28 @@
class CSV::Table
attr_accessor :ancestor
def where_not(*conditions)
- result = CSV::Table.new([])
+ result = prepare_new_table
+
self.each do |record|
counter = 0
conditions.first.each {|key, value| counter += 1 unless record[key] == value.to_s}
result.table << record if counter == conditions.size
end
result
end
+ # Select records which don't match with block
+ def not(&block)
+ result = prepare_new_table
+ result.table.replace(self.table - self.instance_eval(&block).table)
+ result
+ end
+
def where(*conditions)
- result = CSV::Table.new([])
- result.ancestor = self.ancestor || self
+ result = prepare_new_table
self.each do |record|
counter = 0
conditions.first.each {|key, value| counter += 1 if record[key] == value.to_s}
result << record if counter == conditions.size