Class: MARC::Spec::Queries::QueryExecutor

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/marc/spec/queries/query_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Part

#eql?, #hash, #inspect

Constructor Details

#initialize(marc_record, root_query, cache = {}) ⇒ QueryExecutor



12
13
14
15
16
# File 'lib/marc/spec/queries/query_executor.rb', line 12

def initialize(marc_record, root_query, cache = {})
  @marc_record = ensure_type(marc_record, MARC::Record)
  @root_query = root_query
  @cache = cache
end

Instance Attribute Details

#marc_recordObject (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_queryObject (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

Instance Method Details

#any_results?Boolean



30
31
32
# File 'lib/marc/spec/queries/query_executor.rb', line 30

def any_results?
  root_query.any_results?(self, root_fields)
end

#apply_selector(selector, field) ⇒ Object



38
39
40
41
42
43
# File 'lib/marc/spec/queries/query_executor.rb', line 38

def apply_selector(selector, field)
  return [field] unless selector

  cache_key = [selector, field]
  cache[cache_key] ||= selector.apply(field)
end

#apply_tag(tag) ⇒ Object



34
35
36
# File 'lib/marc/spec/queries/query_executor.rb', line 34

def apply_tag(tag)
  cache[tag] ||= tag.apply(marc_record)
end

#condition_met?(condition, context_field, context_result) ⇒ Boolean



45
46
47
48
# File 'lib/marc/spec/queries/query_executor.rb', line 45

def condition_met?(condition, context_field, context_result)
  cond_ctx = ConditionContext.new(context_field, context_result, self)
  condition.met?(cond_ctx)
end

#executeObject



26
27
28
# File 'lib/marc/spec/queries/query_executor.rb', line 26

def execute
  root_query.execute(self, root_fields)
end

#root_fieldsObject



22
23
24
# File 'lib/marc/spec/queries/query_executor.rb', line 22

def root_fields
  @root_fields ||= apply_tag(root_tag)
end

#root_tagObject



18
19
20
# File 'lib/marc/spec/queries/query_executor.rb', line 18

def root_tag
  @root_tag ||= root_query.tag || Tag.new('...')
end