Class: Fbe::Award::Bill

Inherits:
Object
  • Object
show all
Defined in:
lib/fbe/award.rb

Overview

A bill.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBill

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

#varsObject (readonly)

Returns the value of attribute vars.



214
215
216
# File 'lib/fbe/award.rb', line 214

def vars
  @vars
end

Instance Method Details

#greetingObject



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

#pointsObject



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