Class: MARC::Spec::Queries::QueryExecutor
- Inherits:
-
Object
- Object
- MARC::Spec::Queries::QueryExecutor
- Includes:
- Part
- Defined in:
- lib/marc/spec/queries/query_executor.rb
Instance Attribute Summary collapse
-
#marc_record ⇒ Object
readonly
Returns the value of attribute marc_record.
-
#root_fields ⇒ Object
readonly
Returns the value of attribute root_fields.
-
#root_query ⇒ Object
readonly
Returns the value of attribute root_query.
-
#root_tag ⇒ Object
readonly
Returns the value of attribute root_tag.
Instance Method Summary collapse
- #apply_selector(selector, field) ⇒ Object
- #apply_tag(tag) ⇒ Object
- #condition_met?(condition, context_field, context_result) ⇒ Boolean
- #execute ⇒ Object
-
#initialize(marc_record, root, cache = {}) ⇒ QueryExecutor
constructor
A new instance of QueryExecutor.
Methods included from Part
Constructor Details
#initialize(marc_record, root, cache = {}) ⇒ QueryExecutor
Returns a new instance of QueryExecutor.
12 13 14 15 16 17 18 19 |
# File 'lib/marc/spec/queries/query_executor.rb', line 12 def initialize(marc_record, root, cache = {}) @marc_record = ensure_type(marc_record, MARC::Record) @root_query = as_query(root) @cache = cache @root_tag = root_query.tag || Tag.new('...') @root_fields = apply_tag(root_tag) end |
Instance Attribute Details
#marc_record ⇒ Object (readonly)
Returns the value of attribute marc_record.
10 11 12 |
# File 'lib/marc/spec/queries/query_executor.rb', line 10 def marc_record @marc_record end |
#root_fields ⇒ Object (readonly)
Returns the value of attribute root_fields.
10 11 12 |
# File 'lib/marc/spec/queries/query_executor.rb', line 10 def root_fields @root_fields end |
#root_query ⇒ Object (readonly)
Returns the value of attribute root_query.
10 11 12 |
# File 'lib/marc/spec/queries/query_executor.rb', line 10 def root_query @root_query end |
#root_tag ⇒ Object (readonly)
Returns the value of attribute root_tag.
10 11 12 |
# File 'lib/marc/spec/queries/query_executor.rb', line 10 def root_tag @root_tag end |
Instance Method Details
#apply_selector(selector, field) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/marc/spec/queries/query_executor.rb', line 29 def apply_selector(selector, field) return [field] unless selector cache_key = [selector, field] cache[cache_key] ||= selector.apply(field) end |
#apply_tag(tag) ⇒ Object
25 26 27 |
# File 'lib/marc/spec/queries/query_executor.rb', line 25 def apply_tag(tag) cache[tag] ||= tag.apply(marc_record) end |
#condition_met?(condition, context_field, context_result) ⇒ Boolean
36 37 38 39 |
# File 'lib/marc/spec/queries/query_executor.rb', line 36 def condition_met?(condition, context_field, context_result) cond_ctx = ConditionContext.new(context_field, context_result, self) condition.met?(cond_ctx) end |
#execute ⇒ Object
21 22 23 |
# File 'lib/marc/spec/queries/query_executor.rb', line 21 def execute root_query.execute(self, root_fields) end |