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.



303
304
305
306
307
# File 'lib/fbe/award.rb', line 303

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

Instance Attribute Details

#varsObject (readonly)

Returns the value of attribute vars.



301
302
303
# File 'lib/fbe/award.rb', line 301

def vars
  @vars
end

Instance Method Details

#intro(text) ⇒ Object



313
314
315
# File 'lib/fbe/award.rb', line 313

def intro(text)
  @intro = text
end

#let(key, value) ⇒ Object



322
323
324
# File 'lib/fbe/award.rb', line 322

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

#line(line) ⇒ Object



317
318
319
320
# File 'lib/fbe/award.rb', line 317

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

#markdownObject



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/fbe/award.rb', line 326

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



309
310
311
# File 'lib/fbe/award.rb', line 309

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