Class: Fbe::Conclude
- Inherits:
-
Object
- Object
- Fbe::Conclude
- Defined in:
- lib/fbe/conclude.rb
Overview
A concluding block.
You may want to use this class when you want to go through a number of facts in the factbase, applying a certain algorithm to each of them and possibly creating new facts from them.
For example, you want to make a new good fact for every bad fact found:
require 'fbe/conclude' conclude do on '(exists bad)' follow 'when' draw do |n, b| n.good = 'yes!' end end
This snippet will find all facts that have bad property and then create
new facts, letting the block in the #draw deal with them.
- Author
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
Copyright (c) 2024-2026 Zerocracy
- License
MIT
Instance Method Summary collapse
-
#consider {|Factbase::Fact| ... } ⇒ Integer
Take every fact, allowing the given block to process it.
-
#draw {|Array<Factbase::Fact,Factbase::Fact>| ... } ⇒ Integer
Create new fact from every fact found by the query.
-
#follow(props) ⇒ nil
Set the list of properties to copy from the facts found to new facts.
-
#initialize(fb:, judge:, global:, options:, loog:, epoch:, kickoff:) ⇒ Conclude
constructor
Ctor.
-
#lifetime_unaware ⇒ nil
Make this block NOT aware of lifetime limitations.
-
#on(query) ⇒ nil
Set the query that should find the facts in the factbase.
-
#quota_unaware ⇒ nil
Make this block not aware of GitHub API quota.
-
#timeout_unaware ⇒ nil
Make this block NOT aware of timeout limitations.
Constructor Details
#initialize(fb:, judge:, global:, options:, loog:, epoch:, kickoff:) ⇒ Conclude
Ctor.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fbe/conclude.rb', line 69 def initialize(fb:, judge:, global:, options:, loog:, epoch:, kickoff:) @fb = fb @judge = judge @loog = loog @options = @global = global @epoch = epoch @kickoff = kickoff @query = nil @follows = [] @lifetime = true @timeout = true @quota = true end |
Instance Method Details
#consider {|Factbase::Fact| ... } ⇒ Integer
Take every fact, allowing the given block to process it.
For example, you want to add when property to every fact:
require 'fbe/conclude' conclude do on '(always)' consider do |f| f.when = Time.new end end
172 173 174 175 176 177 |
# File 'lib/fbe/conclude.rb', line 172 def consider(&) roll do |_fbt, a| yield(a) nil end end |
#draw {|Array<Factbase::Fact,Factbase::Fact>| ... } ⇒ Integer
Create new fact from every fact found by the query.
For example, you want to conclude a reward from every win fact:
require 'fbe/conclude' conclude do on '(exists win)' follow 'win when' draw do |n, w| n.reward = 10 end end
This snippet will find all facts that have win property and will create
new facts for all of them, passing them one by one in to the block of
the draw, where n would be the new created fact and the w would
be the fact found.
150 151 152 153 154 155 156 |
# File 'lib/fbe/conclude.rb', line 150 def draw(&) roll do |fbt, a| n = fbt.insert fill(n, a, &) n end end |
#follow(props) ⇒ nil
Set the list of properties to copy from the facts found to new facts.
125 126 127 128 |
# File 'lib/fbe/conclude.rb', line 125 def follow(props) raise(Fbe::Error, 'Follow is already set') unless @follows.empty? @follows = props.strip.split.compact end |
#lifetime_unaware ⇒ nil
Make this block NOT aware of lifetime limitations.
When the lifetime is over, the loop will NOT gracefully stop.
99 100 101 |
# File 'lib/fbe/conclude.rb', line 99 def lifetime_unaware @lifetime = false end |
#on(query) ⇒ nil
Set the query that should find the facts in the factbase.
116 117 118 119 |
# File 'lib/fbe/conclude.rb', line 116 def on(query) raise(Fbe::Error, 'Query is already set') unless @query.nil? @query = query end |
#quota_unaware ⇒ nil
Make this block not aware of GitHub API quota.
When the quota is reached, the loop will NOT gracefully stop to avoid hitting GitHub API rate limits.
90 91 92 |
# File 'lib/fbe/conclude.rb', line 90 def quota_unaware @quota = false end |
#timeout_unaware ⇒ nil
Make this block NOT aware of timeout limitations.
When the timeout is over, the loop will NOT gracefully stop.
108 109 110 |
# File 'lib/fbe/conclude.rb', line 108 def timeout_unaware @timeout = false end |