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.
323 324 325 326 327 |
# File 'lib/fbe/award.rb', line 323 def initialize @lines = [] @intro = '' @lets = {} end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
321 322 323 |
# File 'lib/fbe/award.rb', line 321 def vars @vars end |
Instance Method Details
#intro(text) ⇒ Object
333 334 335 |
# File 'lib/fbe/award.rb', line 333 def intro(text) @intro = text end |
#let(key, value) ⇒ Object
342 343 344 |
# File 'lib/fbe/award.rb', line 342 def let(key, value) @lets[key] = value end |
#line(line) ⇒ Object
337 338 339 340 |
# File 'lib/fbe/award.rb', line 337 def line(line) line = line.gsub(/\$\{([a-z_0-9]+)\}/) { |_x| "**#{@lets[Regexp.last_match[1].to_sym]}**" } @lines << line end |
#markdown ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/fbe/award.rb', line 346 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 ').gsub(/\s{2,}/, ' ') end |
#revert(num) ⇒ Object
329 330 331 |
# File 'lib/fbe/award.rb', line 329 def revert(num) @lines.slice!(-num, num) end |