Class: Fbe::Award::Policy
- Inherits:
-
Object
- Object
- Fbe::Award::Policy
- Defined in:
- lib/fbe/award.rb
Overview
A policy.
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
- #intro(text) ⇒ Object
- #let(key, value) ⇒ Object
- #line(line) ⇒ Object
- #markdown ⇒ Object
- #revert(num) ⇒ Object
Constructor Details
#initialize ⇒ Policy
Returns a new instance of Policy.
302 303 304 305 306 |
# File 'lib/fbe/award.rb', line 302 def initialize @lines = [] @intro = '' @lets = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
300 301 302 |
# File 'lib/fbe/award.rb', line 300 def vars @vars end |
Instance Method Details
#intro(text) ⇒ Object
312 313 314 |
# File 'lib/fbe/award.rb', line 312 def intro(text) @intro = text end |
#let(key, value) ⇒ Object
321 322 323 |
# File 'lib/fbe/award.rb', line 321 def let(key, value) @lets[key] = value end |
#line(line) ⇒ Object
316 317 318 319 |
# File 'lib/fbe/award.rb', line 316 def line(line) line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" } @lines << line end |
#markdown ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/fbe/award.rb', line 325 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
308 309 310 |
# File 'lib/fbe/award.rb', line 308 def revert(num) @lines.slice!(-num, num) end |