Sha256: c9b4e5db83d1ac42d9200cfabae71b53cc3d92ff5f318161fc4567388524c7a1
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
# Creates a Section. # A section have a name and contains other elements. # Sections could be nested inside anothers class ReportBuilder::Section @@n=1 attr_reader :parent, :elements, :name def initialize(options=Hash.new, &block) if !options.has_key? :name @name="Section #{@@n}" @@n+=1 else @name=options[:name] end @parent = nil @elements = [] if block add(block) end end def parent=(sect) if sect.is_a? ReportBuilder::Section @parent=sect else raise ArgumentError("Parent should be a Section") end end def report_building_text(builder) builder.text(("="*builder.parse_level)+" "+name) builder.parse_cycle(self) end def report_building_html(g) htag="h#{g.parse_level+1}" anchor=g.toc_entry(name) g.html "<div class='section'><#{htag}>#{name}</#{htag}><a name='#{anchor}'></a>" g.parse_cycle(self) g.html "</div>" end def report_building_rtf(g) level=g.parse_level g.header(level,name) g.parse_cycle(self) end def add(element) if element.is_a? ReportBuilder::Section element.parent=self end @elements.push(element) end end
Version data entries
7 entries across 7 versions & 1 rubygems