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.
303 304 305 306 307 |
# File 'lib/fbe/award.rb', line 303 def initialize @lines = [] @intro = '' @lets = {} end |
Instance Attribute Details
#vars ⇒ Object (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 |
#markdown ⇒ Object
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 |