Class: Fbe::Award
- Inherits:
-
Object
- Object
- Fbe::Award
- Defined in:
- lib/fbe/award.rb
Overview
A generator of awards.
First, you should create a bylaw, using the same Lisp-ish syntax as we use in queries to a Factbase, for example:
require 'fbe/award'
a = Fbe::Award.new('(award (in loc "lines") (give (times loc 5) "for LoC"))')
Then, you can either get a bill from it:
b = a.bill(loc: 345)
puts b.points # how many points to reward, a number
puts b.greeting # how to explain the reward, a text
Or else, you can get a bylaw text:
p = a.bylaw
puts p.markdown # Markdown of the bylaw
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Classes: BTerm, Bill, Bylaw, PTerm
Instance Method Summary collapse
-
#bill(vars = {}) ⇒ Fbe::Award::Bill
Build a bill object from this award query.
-
#bylaw ⇒ Fbe::Award::Bylaw
Build a bylaw object from this award query.
-
#initialize(query = nil, judge: $judge, global: $global, options: $options, loog: $loog) ⇒ Award
constructor
Ctor.
Constructor Details
#initialize(query = nil, judge: $judge, global: $global, options: $options, loog: $loog) ⇒ Award
Ctor.
35 36 37 38 |
# File 'lib/fbe/award.rb', line 35 def initialize(query = nil, judge: $judge, global: $global, options: $options, loog: $loog) query = Fbe.pmp(fb: Fbe.fb, global:, options:, loog:).hr.send(judge.tr('-', '_')) if query.nil? @query = query end |
Instance Method Details
#bill(vars = {}) ⇒ Fbe::Award::Bill
Build a bill object from this award query.
43 44 45 46 47 48 49 |
# File 'lib/fbe/award.rb', line 43 def bill(vars = {}) term = Factbase::Syntax.new(Factbase.new, @query, term: Fbe::Award::BTerm).to_term bill = Bill.new vars.each { |k, v| bill.set(k, v) } term.bill_to(bill) bill end |