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.
216 217 218 219 |
# File 'lib/fbe/award.rb', line 216 def initialize @lines = [] @vars = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
214 215 216 |
# File 'lib/fbe/award.rb', line 214 def vars @vars end |
Instance Method Details
#greeting ⇒ Object
235 236 237 238 |
# File 'lib/fbe/award.rb', line 235 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
225 226 227 228 229 |
# File 'lib/fbe/award.rb', line 225 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
231 232 233 |
# File 'lib/fbe/award.rb', line 231 def points @lines.map { |l| l[:v] }.inject(&:+).to_i end |
#set(var, value) ⇒ Object
221 222 223 |
# File 'lib/fbe/award.rb', line 221 def set(var, value) @vars[var] = value end |