class MARC::Spec::Queries::ConditionContext

Attributes

context_field[R]
context_result[R]
executor[R]

Public Class Methods

new(context_field, context_result, executor) click to toggle source
# File lib/marc/spec/queries/condition_context.rb, line 11
def initialize(context_field, context_result, executor)
  @context_field = context_field
  @context_result = context_result
  @executor = executor
end

Public Instance Methods

operand_value(operand, implicit: false) click to toggle source
# File lib/marc/spec/queries/condition_context.rb, line 17
def operand_value(operand, implicit: false)
  return operand_value(context_result) if implicit && operand.nil?

  raw_value = operand_value_raw(operand)
  is_boolean = [true, false].include?(raw_value)
  is_boolean ? raw_value : as_string(raw_value)
end

Private Instance Methods

as_string(op_val) click to toggle source
# File lib/marc/spec/queries/condition_context.rb, line 35
def as_string(op_val)
  return unless op_val
  return op_val if op_val.is_a?(String)
  return op_val.value if op_val.respond_to?(:value) && !op_val.is_a?(MARC::DataField)
  return op_val.map { |v| as_string(v) } if op_val.is_a?(Array)
end
operand_value_raw(operand) click to toggle source
# File lib/marc/spec/queries/condition_context.rb, line 27
def operand_value_raw(operand)
  return operand.str_exact if operand.is_a?(ComparisonString)
  return operand.met?(self) if operand.is_a?(Condition)
  return operand.execute(executor, [context_field], context_result) if operand.is_a?(Query)

  operand
end