Class: Fbe::Award::Bill
- Inherits:
-
Object
- Object
- Fbe::Award::Bill
- Defined in:
- lib/fbe/award.rb
Overview
A bill.
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #greeting ⇒ Object
-
#initialize ⇒ Bill
constructor
A new instance of Bill.
- #line(value, text) ⇒ Object
- #points ⇒ Object
- #set(var, value) ⇒ Object
Constructor Details
#initialize ⇒ Bill
Returns a new instance of Bill.
306 307 308 309 |
# File 'lib/fbe/award.rb', line 306 def initialize @lines = [] @vars = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
304 305 306 |
# File 'lib/fbe/award.rb', line 304 def vars @vars end |
Instance Method Details
#greeting ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/fbe/award.rb', line 325 def greeting items = @lines.map { |l| "#{format('%+d', l[:v])} #{l[:t]}" } case items.size when 0 "You've earned nothing. " when 1 "You've earned #{format('%+d', points)} points. " else "You've earned #{format('%+d', points)} points for this: #{items.join('; ')}. " end end |
#line(value, text) ⇒ Object
315 316 317 318 319 |
# File 'lib/fbe/award.rb', line 315 def line(value, text) return if value.zero? text = text.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| @vars[Regexp.last_match[1].to_sym] } @lines << { v: value, t: text } end |
#points ⇒ Object
321 322 323 |
# File 'lib/fbe/award.rb', line 321 def points @lines.sum { |l| l[:v] }.to_f.round.to_i end |
#set(var, value) ⇒ Object
311 312 313 |
# File 'lib/fbe/award.rb', line 311 def set(var, value) @vars[var] = value end |