Class: Factbase::Query

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

Overview

Query.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

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.

Yields:

  • (Fact)

    Facts 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_aArray

Turn it into an array. rubocop:disable Style/MapIntoArray

Returns:

  • (Array)

    All facts in an array



52
53
54
55
56
# File 'lib/factbase/query.rb', line 52

def to_a
  array = []
  each { |f| array << f }
  array
end