Class: Container

Inherits:
Object
  • Object
show all
Defined in:
lib/yesroff/text.rb

Direct Known Subclasses

Paragraph, Span

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style, parent = nil, contents = []) ⇒ Container

Returns a new instance of Container.



80
81
82
83
84
# File 'lib/yesroff/text.rb', line 80

def initialize(style, parent=nil, contents=[])
  @style = style
  @contents = contents
  @parent = parent
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



78
79
80
# File 'lib/yesroff/text.rb', line 78

def contents
  @contents
end

#parentObject

Returns the value of attribute parent.



78
79
80
# File 'lib/yesroff/text.rb', line 78

def parent
  @parent
end

#styleObject

Returns the value of attribute style.



78
79
80
# File 'lib/yesroff/text.rb', line 78

def style
  @style
end

Instance Method Details

#<<(content) ⇒ Object



86
87
88
# File 'lib/yesroff/text.rb', line 86

def <<(content)
  @contents << content
end

#lengthObject



90
91
92
93
94
# File 'lib/yesroff/text.rb', line 90

def length
  l = 0
  @contents.each {|kid| l += kid.length}
  l
end

#render(w) ⇒ Object



96
97
98
99
100
101
# File 'lib/yesroff/text.rb', line 96

def render(w)
  #log "========= rendering #{self.class} size: #{contents.size}"
  #pp contents
  #puts "Rendering:"
  contents.each {|c|  c.render(w)}
end

#to_sObject



103
104
105
106
107
108
109
# File 'lib/yesroff/text.rb', line 103

def to_s
  result = "Container #{style}"
  if @contents
    result += @contents.join(' ')      
  end
  result
end