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.



233
234
235
236
# File 'lib/fbe/award.rb', line 233

def initialize
  @lines = []
  @vars = {}
end

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



231
232
233
# File 'lib/fbe/award.rb', line 231

def vars
  @vars
end

Instance Method Details

#greetingObject



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

#pointsObject



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