Class: Archsight::Query::Query
- Inherits:
-
Object
- Object
- Archsight::Query::Query
- Defined in:
- lib/archsight/query.rb
Overview
Main Query class - entry point for parsing and evaluating queries
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#filter(database) ⇒ Object
Filter all instances from database matching this query.
-
#initialize(source) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
-
#kind_filter ⇒ Object
Return the kind filter if present (for optimization).
-
#matches?(instance, database:) ⇒ Boolean
Check if a single instance matches this query.
-
#to_s ⇒ Object
Pretty print for debugging.
Constructor Details
#initialize(source) ⇒ Query
Returns a new instance of Query.
19 20 21 22 |
# File 'lib/archsight/query.rb', line 19 def initialize(source) @source = source @ast = parse(source) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
17 18 19 |
# File 'lib/archsight/query.rb', line 17 def ast @ast end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/archsight/query.rb', line 17 def source @source end |
Instance Method Details
#filter(database) ⇒ Object
Filter all instances from database matching this query
31 32 33 34 |
# File 'lib/archsight/query.rb', line 31 def filter(database) evaluator = Evaluator.new(database) evaluator.filter(@ast) end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/archsight/query.rb', line 46 def inspect "#<Query source=#{@source.inspect} kind_filter=#{kind_filter.inspect}>" end |
#kind_filter ⇒ Object
Return the kind filter if present (for optimization)
37 38 39 |
# File 'lib/archsight/query.rb', line 37 def kind_filter @ast.kind_filter end |
#matches?(instance, database:) ⇒ Boolean
Check if a single instance matches this query
25 26 27 28 |
# File 'lib/archsight/query.rb', line 25 def matches?(instance, database:) evaluator = Evaluator.new(database) evaluator.matches?(@ast, instance) end |
#to_s ⇒ Object
Pretty print for debugging
42 43 44 |
# File 'lib/archsight/query.rb', line 42 def to_s "Query(#{@source})" end |