Class: KQL::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/kql/query.rb

Direct Known Subclasses

Mapping

Defined Under Namespace

Classes: Context, SelectedNode, TopContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alternatives) ⇒ Query

Returns a new instance of Query.



5
6
7
# File 'lib/kql/query.rb', line 5

def initialize(alternatives)
  @alternatives = alternatives
end

Instance Attribute Details

#alternativesObject (readonly)

Returns the value of attribute alternatives.



3
4
5
# File 'lib/kql/query.rb', line 3

def alternatives
  @alternatives
end

Instance Method Details

#==(other) ⇒ Object



9
10
11
12
13
# File 'lib/kql/query.rb', line 9

def ==(other)
  return false unless other.is_a?(Query)

  other.alternatives == alternatives
end

#execute(document) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/kql/query.rb', line 15

def execute(document)
  alternatives.flat_map do |alt|
    alt.execute(TopContext.new(document))
       .nodes
       .uniq { |n| n.__id__ }
  end
end