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, 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_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_fieldsObject (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_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

#root_tagObject (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

Returns:

  • (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

#executeObject



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

def execute
  root_query.execute(self, root_fields)
end