Class: Oinky::Detail::Builder

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/oinky/oc_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(lwidth = 4, lcount = 0) ⇒ Builder

Returns a new instance of Builder.



12
13
14
15
16
# File 'lib/oinky/oc_builder.rb', line 12

def initialize(lwidth = 4, lcount = 0)
  @lwidth = lwidth
  @lcount = lcount
  @str = []
end

Instance Method Details

#<<(s) ⇒ Object



25
26
27
# File 'lib/oinky/oc_builder.rb', line 25

def <<(s)
  write(s, 0)
end

#eachObject



38
39
40
# File 'lib/oinky/oc_builder.rb', line 38

def each
  return @str.each
end

#formatObject



34
35
36
# File 'lib/oinky/oc_builder.rb', line 34

def format
  return (@str * "\n") + "\n"
end

#next(s1, s2) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/oinky/oc_builder.rb', line 17

def next(s1, s2)
  self << s1
  @lcount += 1
  yield
  @lcount -= 1
  self << s2
  self
end

#write(s, ldelta) ⇒ Object



28
29
30
31
32
# File 'lib/oinky/oc_builder.rb', line 28

def write(s, ldelta) 
  l = @lcount + ldelta
  @str << ((' ' * l * @lwidth) + s)
  self
end