Class: Factbase::Query
- Inherits:
-
Object
- Object
- Factbase::Query
- Defined in:
- lib/factbase/query.rb
Overview
Query.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#each {|Fact| ... } ⇒ Object
Iterate them one by one.
-
#initialize(maps, mutex, query) ⇒ Query
constructor
A new instance of Query.
-
#to_a ⇒ Array
Turn it into an array.
Constructor Details
#initialize(maps, mutex, query) ⇒ Query
Returns a new instance of Query.
32 33 34 35 36 |
# File 'lib/factbase/query.rb', line 32 def initialize(maps, mutex, query) @maps = maps @mutex = mutex @query = query end |
Instance Method Details
#each {|Fact| ... } ⇒ Object
Iterate them one by one.
40 41 42 43 44 45 46 47 |
# File 'lib/factbase/query.rb', line 40 def each term = Factbase::Syntax.new(@query).to_term @maps.each do |m| f = Factbase::Fact.new(@mutex, m) next unless term.matches?(f) yield f end end |
#to_a ⇒ Array
Turn it into an array. rubocop:disable Style/MapIntoArray
52 53 54 55 56 |
# File 'lib/factbase/query.rb', line 52 def to_a array = [] each { |f| array << f } array end |