Class: MARC::Spec::Queries::Operator
- Inherits:
-
TypesafeEnum::Base
- Object
- TypesafeEnum::Base
- MARC::Spec::Queries::Operator
- Defined in:
- lib/marc/spec/queries/operator.rb
Overview
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
Class Method Summary collapse
Instance Method Summary collapse
-
#binary? ⇒ Boolean
———————————————————— Operator.
- #logical? ⇒ Boolean
- #op_str ⇒ String
- #to_expression(left, right) ⇒ Object
-
#to_s ⇒ Object
———————————————————— Object overrides.
Class Method Details
.from_str(op_str) ⇒ Object
90 91 92 93 94 |
# 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 |
Instance Method Details
#binary? ⇒ Boolean
Operator
100 101 102 |
# File 'lib/marc/spec/queries/operator.rb', line 100 def binary? ![Operator::EXIST, Operator::NEXIST].include?(self) end |
#logical? ⇒ Boolean
104 105 106 |
# File 'lib/marc/spec/queries/operator.rb', line 104 def logical? [Operator::AND, Operator::OR].include?(self) end |
#op_str ⇒ String
116 117 118 119 |
# File 'lib/marc/spec/queries/operator.rb', line 116 def op_str # noinspection RubyMismatchedReturnType value end |
#to_expression(left, right) ⇒ Object
121 122 123 124 125 |
# 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 ⇒ Object
Object overrides
111 112 113 |
# File 'lib/marc/spec/queries/operator.rb', line 111 def to_s op_str end |