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 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 '(exist bad)'
follow 'when'
draw on |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 © 2024 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:) ⇒ Conclude
constructor
Ctor.
-
#on(query) ⇒ nil
Set the query that should find the facts in the factbase.
-
#quota_aware ⇒ nil
Make this block aware of GitHub API quota.
Constructor Details
#initialize(fb:, judge:, global:, options:, loog:) ⇒ Conclude
Ctor.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fbe/conclude.rb', line 74 def initialize(fb:, judge:, global:, options:, loog:) @fb = fb @judge = judge @loog = loog @options = @global = global @query = nil @follows = [] @quota_aware = false 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 on |f|
f.when = Time.new
end
end
153 154 155 156 157 158 |
# File 'lib/fbe/conclude.rb', line 153 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 '(exist win)'
follow 'win when'
draw on |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.
131 132 133 134 135 136 137 |
# File 'lib/fbe/conclude.rb', line 131 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.
107 108 109 |
# File 'lib/fbe/conclude.rb', line 107 def follow(props) @follows = props.strip.split.compact end |
#on(query) ⇒ nil
Set the query that should find the facts in the factbase.
98 99 100 101 |
# File 'lib/fbe/conclude.rb', line 98 def on(query) raise 'Query is already set' unless @query.nil? @query = query end |
#quota_aware ⇒ nil
Make this block aware of GitHub API quota.
When the quota is reached, the loop will gracefully stop.
90 91 92 |
# File 'lib/fbe/conclude.rb', line 90 def quota_aware @quota_aware = true end |