Class: ReportBuilder::Section
- Inherits:
-
Object
- Object
- ReportBuilder::Section
- Defined in:
- lib/reportbuilder/section.rb
Overview
Creates a Section. A section have a name and contains other elements. Sections could be nested inside anothers
Constant Summary collapse
- @@n =
1
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add(element) ⇒ Object
-
#initialize(options = Hash.new, &block) ⇒ Section
constructor
A new instance of Section.
- #report_building_html(g) ⇒ Object
- #report_building_pdf(g) ⇒ Object
- #report_building_rtf(g) ⇒ Object
- #report_building_text(builder) ⇒ Object
Constructor Details
#initialize(options = Hash.new, &block) ⇒ Section
Returns a new instance of Section.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/reportbuilder/section.rb', line 8 def initialize(=Hash.new, &block) if !.has_key? :name @name="Section #{@@n}" @@n+=1 else @name=[:name] end @parent = nil @elements = [] if block add(block) end end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
7 8 9 |
# File 'lib/reportbuilder/section.rb', line 7 def elements @elements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/reportbuilder/section.rb', line 7 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/reportbuilder/section.rb', line 7 def parent @parent end |
Instance Method Details
#add(element) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/reportbuilder/section.rb', line 51 def add(element) if element.is_a? ReportBuilder::Section element.parent=self end @elements.push(element) end |
#report_building_html(g) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/reportbuilder/section.rb', line 34 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 |
#report_building_pdf(g) ⇒ Object
46 47 48 49 50 |
# File 'lib/reportbuilder/section.rb', line 46 def report_building_pdf(g) level=g.parse_level g.header(level, name) g.parse_cycle(self) end |
#report_building_rtf(g) ⇒ Object
41 42 43 44 45 |
# File 'lib/reportbuilder/section.rb', line 41 def report_building_rtf(g) level=g.parse_level g.header(level, name) g.parse_cycle(self) end |
#report_building_text(builder) ⇒ Object
29 30 31 32 |
# File 'lib/reportbuilder/section.rb', line 29 def report_building_text(builder) builder.text(("="*builder.parse_level)+" #{name}") builder.parse_cycle(self) end |