Class: SlotMachine::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/slot_machine/builder.rb

Overview

A builder class base for the builder of the different partials

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Builder

Returns a new instance of Builder.



6
7
8
# File 'lib/slot_machine/builder.rb', line 6

def initialize(template)
  @template = template
end

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



4
5
6
# File 'lib/slot_machine/builder.rb', line 4

def output_buffer
  @output_buffer
end

Instance Method Details

#append_slot(name = :main, string = nil, &block) ⇒ Object Also known as: slot

append the named slot



11
12
13
14
# File 'lib/slot_machine/builder.rb', line 11

def append_slot(name = :main, string = nil, &block)
  slots[name].concat(get_buffer(string, &block))
  nil # why the fuck do I need this. It shouldn't put anything in the buffer but it does.
end

#get_buffer(string = nil, &block) ⇒ Object

capture the block if ther is one



23
24
25
26
27
# File 'lib/slot_machine/builder.rb', line 23

def get_buffer(string = nil, &block)
  return string unless block

  @template.capture { yield }
end

#slotsObject

attribute reader



18
19
20
# File 'lib/slot_machine/builder.rb', line 18

def slots
  @slots ||= Hash.new { |h, k| h[k] = ActiveSupport::SafeBuffer.new('') }
end