Class: SimplerDB::QueryEvaluator
- Inherits:
-
Dhaka::Evaluator
- Object
- Dhaka::Evaluator
- SimplerDB::QueryEvaluator
- Defined in:
- lib/simplerdb/query_language.rb
Overview
The query evaluator. This class acts on the parse tree and will return a list of item names that match the query from the evaluate method.
Instance Method Summary collapse
- #all_items ⇒ Object
-
#do_comparison(identifier, op, constant, negate = false) ⇒ Object
Apply the given comparison params to every item in the domain.
-
#initialize(domain = nil) ⇒ QueryEvaluator
constructor
A new instance of QueryEvaluator.
- #val(node) ⇒ Object
Constructor Details
#initialize(domain = nil) ⇒ QueryEvaluator
Returns a new instance of QueryEvaluator.
150 151 152 153 154 |
# File 'lib/simplerdb/query_language.rb', line 150 def initialize(domain = nil) @domain = domain @predicate_identifier = nil @all_items = nil end |
Instance Method Details
#all_items ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/simplerdb/query_language.rb', line 237 def all_items unless @all_items @all_items = @domain.items.collect { |k,v| k }.to_set end return @all_items end |
#do_comparison(identifier, op, constant, negate = false) ⇒ Object
Apply the given comparison params to every item in the domain
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/simplerdb/query_language.rb', line 246 def do_comparison(identifier, op, constant, negate = false) results = Set.new if @domain @domain.items.each_value do |item| attrs = item.attributes[identifier] attrs.each do |attr| match = op.call(constant, attr.value) if (match && !negate) || (negate && !match) results << item break end end end end results end |
#val(node) ⇒ Object
233 234 235 |
# File 'lib/simplerdb/query_language.rb', line 233 def val(node) node.token.value.to_s[1..-2] end |