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.
233 234 235 236 |
# File 'lib/fbe/award.rb', line 233 def initialize @lines = [] @vars = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
231 232 233 |
# File 'lib/fbe/award.rb', line 231 def vars @vars end |
Instance Method Details
#greeting ⇒ Object
252 253 254 255 |
# File 'lib/fbe/award.rb', line 252 def greeting items = @lines.map { |l| "#{format('%+d', l[:v])} #{l[:t]}" } "You've earned #{format('%+d', points)} points for this: #{items.join('; ')}. " end |
#line(value, text) ⇒ Object
242 243 244 245 246 |
# File 'lib/fbe/award.rb', line 242 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
248 249 250 |
# File 'lib/fbe/award.rb', line 248 def points @lines.map { |l| l[:v] }.inject(&:+).to_i end |
#set(var, value) ⇒ Object
238 239 240 |
# File 'lib/fbe/award.rb', line 238 def set(var, value) @vars[var] = value end |