class MARC::Spec::Queries::Operator
NOTE: && and || are not defined in the MARCspec standard but are
implementation details of repeated (AND) and chained (OR) subspecs -- see https://marcspec.github.io/MARCspec/marc-spec.html#general
Public Class Methods
from_str(op_str)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 90 def from_str(op_str) Operator.find_by_value(op_str.to_s).tap do |op| raise ArgumentError, "No such operator: #{op_str}" unless op end end
Public Instance Methods
apply(lr, rr)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 15 def apply(lr, rr) return false if rr.nil? return rarr_eq?(lr, rr) if rr.is_a?(Array) return larr_eq?(lr, rr) if lr.is_a?(Array) lr == rr end
binary?()
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 100 def binary? ![Operator::EXIST, Operator::NEXIST].include?(self) end
larr_eq?(larr, rr)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 23 def larr_eq?(larr, rr) larr.any? { |l| apply(l, rr) } end
larr_incl?(larr, rr)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 47 def larr_incl?(larr, rr) larr.any? { |l| apply(l, rr) } end
logical?()
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 104 def logical? [Operator::AND, Operator::OR].include?(self) end
op_str()
click to toggle source
@return [String]
# File lib/marc/spec/queries/operator.rb, line 116 def op_str # noinspection RubyMismatchedReturnType value end
rarr_eq?(lr, rarr)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 27 def rarr_eq?(lr, rarr) rarr.any? { |r| apply(lr, r) } end
rarr_incl?(lr, rarr)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 51 def rarr_incl?(lr, rarr) rarr.any? { |r| apply(lr, r) } end
to_expression(left, right)
click to toggle source
# File lib/marc/spec/queries/operator.rb, line 121 def to_expression(left, right) return ["(#{left})", self, "(#{right})"].join if logical? [left, self, right].join end
to_s()
click to toggle source
Object overrides
# File lib/marc/spec/queries/operator.rb, line 111 def to_s op_str end