Module: NoSE::Backend::FileBackend::RowMatcher

Included in:
DeleteStatementStep, IndexLookupStatementStep
Defined in:
lib/nose/backend/file.rb

Overview

Provide some helper functions which allow the matching of rows based on a set of list of conditions

Instance Method Summary collapse

Instance Method Details

#row_matches?(row, conditions) ⇒ Boolean

Check if a row matches the given condition

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/nose/backend/file.rb', line 85

def row_matches?(row, conditions)
  row_matches_eq?(row, conditions) &&
    row_matches_range?(row, conditions)
end

#row_matches_eq?(row, conditions) ⇒ Boolean

Check if a row matches the given condition on equality predicates

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/nose/backend/file.rb', line 92

def row_matches_eq?(row, conditions)
  @eq_fields.all? do |field|
    row[field.id] == conditions.find { |c| c.field == field }.value
  end
end

#row_matches_range?(row, conditions) ⇒ Boolean

Check if a row matches the given condition on the range predicate

Returns:

  • (Boolean)


100
101
102
103
104
105
# File 'lib/nose/backend/file.rb', line 100

def row_matches_range?(row, conditions)
  return true if @range_field.nil?

  range_cond = conditions.find { |c| c.field == @range_field }
  row[@range_field.id].send range_cond.operator, range_cond.value
end