Class: Fbe::Award::Policy

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

Overview

A policy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePolicy

Returns a new instance of Policy.



277
278
279
280
281
# File 'lib/fbe/award.rb', line 277

def initialize
  @lines = []
  @intro = ''
  @lets = {}
end

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



275
276
277
# File 'lib/fbe/award.rb', line 275

def vars
  @vars
end

Instance Method Details

#intro(text) ⇒ Object



287
288
289
# File 'lib/fbe/award.rb', line 287

def intro(text)
  @intro = text
end

#let(key, value) ⇒ Object



296
297
298
# File 'lib/fbe/award.rb', line 296

def let(key, value)
  @lets[key] = value
end

#line(line) ⇒ Object



291
292
293
294
# File 'lib/fbe/award.rb', line 291

def line(line)
  line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| @lets[Regexp.last_match[1].to_sym] }
  @lines << line
end

#markdownObject



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/fbe/award.rb', line 300

def markdown
  pars = []
  pars << "#{@intro}." unless @intro.empty?
  pars << 'Here is how it\'s calculated:'
  if @lines.size == 1
    pars << "Just #{@lines.first}."
  else
    pars += @lines.each_with_index.map { |t, i| "#{i.zero? ? 'First' : 'Then'}, #{t}." }
  end
  pars.join(' ').gsub('. Then, award ', ', and award ')
end

#revert(num) ⇒ Object



283
284
285
# File 'lib/fbe/award.rb', line 283

def revert(num)
  @lines.slice!(-num, num)
end