Class: Cassandra::Mocks::Statement::Comparitor
- Inherits:
-
Struct
- Object
- Struct
- Cassandra::Mocks::Statement::Comparitor
- Defined in:
- lib/cassandra_mocks/statement/comparitor.rb
Constant Summary collapse
- COMPARISON_MAP =
{ lt: [-1], le: [-1, 0], eq: [0], ge: [0, 1], gt: [1] }
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #check_against(row) ⇒ Object
- #check_against_array(row_values, index = 0, prev_result = false) ⇒ Object
-
#initialize(*args) ⇒ Comparitor
constructor
A new instance of Comparitor.
Constructor Details
#initialize(*args) ⇒ Comparitor
Returns a new instance of Comparitor.
14 15 16 17 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 14 def initialize(*args) super @comparitor = COMPARISON_MAP[operation] end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column
4 5 6 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 4 def column @column end |
#operation ⇒ Object
Returns the value of attribute operation
4 5 6 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 4 def operation @operation end |
#value ⇒ Object
Returns the value of attribute value
4 5 6 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 4 def value @value end |
Instance Method Details
#check_against(row) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 19 def check_against(row) if column.is_a?(Array) check_against_array(row[column]) else @comparitor.include?(row[column] <=> value) end end |
#check_against_array(row_values, index = 0, prev_result = false) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cassandra_mocks/statement/comparitor.rb', line 27 def check_against_array(row_values, index = 0, prev_result = false) row_value = row_values[index] comparison_value = value[index] return prev_result unless row_value comparison = @comparitor.include?(row_value <=> comparison_value) return comparison if row_value != comparison_value check_against_array(row_values, index+1, comparison) end |