Class: Oinky::Detail::Builder
- Inherits:
-
Object
- Object
- Oinky::Detail::Builder
- Includes:
- Enumerable
- Defined in:
- lib/oinky/oc_builder.rb
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #each ⇒ Object
- #format ⇒ Object
-
#initialize(lwidth = 4, lcount = 0) ⇒ Builder
constructor
A new instance of Builder.
- #next(s1, s2) ⇒ Object
- #write(s, ldelta) ⇒ Object
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 |
#each ⇒ Object
38 39 40 |
# File 'lib/oinky/oc_builder.rb', line 38 def each return @str.each end |
#format ⇒ Object
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 |