Class: Factbase::Sprintf

Inherits:
TermBase show all
Defined in:
lib/factbase/terms/sprintf.rb

Overview

Format term.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Sprintf



14
15
16
17
# File 'lib/factbase/terms/sprintf.rb', line 14

def initialize(operands)
  super()
  @operands = operands
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ String

Evaluate term on a fact.



24
25
26
27
28
# File 'lib/factbase/terms/sprintf.rb', line 24

def evaluate(fact, maps, fb)
  fmt = _values(0, fact, maps, fb)[0]
  ops = (1..(@operands.length - 1)).map { |i| _values(i, fact, maps, fb)&.first }
  format(*([fmt] + ops))
end