class Fbe::Conclude

License
MIT
Copyright
Copyright © 2024-2025 Zerocracy
Author

Yegor Bugayenko (yegor256@gmail.com)
new facts, letting the block in the {Fbe::Conclude#draw} deal with them.
This snippet will find all facts that have bad property and then create
end
end
n.good = ‘yes!’
draw on |n, b|
follow ‘when’
on ‘(exist bad)’
conclude do
require ‘fbe/conclude’
For example, you want to make a new good fact for every bad fact found:
and possibly creating new facts from them.
of facts in the factbase, applying certain algorithm to each of them
You may want to use this class when you want to go through a number
A concluding block.

def consider(&)

Returns:
  • (Integer) - The count of the facts processed

Other tags:
    Yield: - The next fact found by the query
def consider(&)
  roll do |_fbt, a|
    yield a
    nil
  end
end

def draw(&)

Returns:
  • (Integer) - The count of the facts processed

Other tags:
    Yield: - New fact and seen fact
def draw(&)
  roll do |fbt, a|
    n = fbt.insert
    fill(n, a, &)
    n
  end
end

def fill(fact, prev)

def fill(fact, prev)
  @follows.each do |follow|
    v = prev.send(follow)
    fact.send(:"#{follow}=", v)
  end
  r = yield fact, prev
  return unless r.is_a?(String)
  fact.details = r
  fact.what = @judge
end

def follow(props)

Returns:
  • (nil) - Nothing

Parameters:
  • props (Arra) -- List of property names
def follow(props)
  @follows = props.strip.split.compact
end

def initialize(fb:, judge:, global:, options:, loog:)

Parameters:
  • loog (Loog) -- The logging facility
  • options (Judges::Options) -- The options coming from the +judges+ tool
  • global (Hash) -- The hash for global caching
  • judge (String) -- The name of the judge, from the +judges+ tool
  • fb (Factbase) -- The factbase
def initialize(fb:, judge:, global:, options:, loog:)
  @fb = fb
  @judge = judge
  @loog = loog
  @options = options
  @global = global
  @query = nil
  @follows = []
  @quota_aware = false
end

def on(query)

Returns:
  • (nil) - Nothing

Parameters:
  • query (String) -- The query
def on(query)
  raise 'Query is already set' unless @query.nil?
  @query = query
end

def quota_aware

Returns:
  • (nil) - Nothing
def quota_aware
  @quota_aware = true
end

def roll(&)

Returns:
  • (Integer) - The count of the facts seen

Other tags:
    Yield: - The next fact found by the query
def roll(&)
  passed = 0
  catch :stop do
    @fb.txn do |fbt|
      fbt.query(@query).each do |a|
        throw :stop if @quota_aware && Fbe.octo(loog: @loog, options: @options, global: @global).off_quota
        n = yield fbt, a
        @loog.info("#{n.what}: #{n.details}") unless n.nil?
        passed += 1
      end
    end
  end
  @loog.debug("Found and processed #{passed} facts by: #{@query}")
  passed
end