Class: Factbase::IndexedQuery
- Inherits:
-
Object
- Object
- Factbase::IndexedQuery
- Includes:
- Enumerable
- Defined in:
- lib/factbase/indexed/indexed_query.rb
Overview
Query with an index, a decorator of another query.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2026 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#delete!(fb = @fb) ⇒ Integer
Delete all facts that match the query.
-
#each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
-
#initialize(origin, idx, fb, fresh) ⇒ IndexedQuery
constructor
Constructor.
-
#one(fb = @fb, params = {}) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
-
#to_s ⇒ String
Print it as a string.
Constructor Details
#initialize(origin, idx, fb, fresh) ⇒ IndexedQuery
Constructor.
21 22 23 24 25 26 |
# File 'lib/factbase/indexed/indexed_query.rb', line 21 def initialize(origin, idx, fb, fresh) @origin = origin @idx = idx @fb = fb @fresh = fresh end |
Instance Method Details
#delete!(fb = @fb) ⇒ Integer
Delete all facts that match the query.
59 60 61 |
# File 'lib/factbase/indexed/indexed_query.rb', line 59 def delete!(fb = @fb) @origin.delete!(fb).tap { @idx.clear } end |
#each(fb = @fb, params = {}) {|Fact| ... } ⇒ Integer
Iterate facts one by one.
38 39 40 41 42 43 44 45 46 |
# File 'lib/factbase/indexed/indexed_query.rb', line 38 def each(fb = @fb, params = {}) return to_enum(__method__, fb, params) unless block_given? n = 0 @origin.each(fb, params) do |f| yield(Factbase::IndexedFact.new(f, @idx, @fresh)) n += 1 end n end |
#one(fb = @fb, params = {}) ⇒ String|Integer|Float|Time|Array|NilClass
Read a single value.
52 53 54 |
# File 'lib/factbase/indexed/indexed_query.rb', line 52 def one(fb = @fb, params = {}) @origin.one(fb, params) end |
#to_s ⇒ String
Print it as a string.
30 31 32 |
# File 'lib/factbase/indexed/indexed_query.rb', line 30 def to_s @origin.to_s end |