Class: ODFReport::Nestable
- Inherits:
-
Object
- Object
- ODFReport::Nestable
- Defined in:
- lib/odf-report/nestable.rb
Instance Method Summary collapse
- #add_field(name, data_field = nil, &block) ⇒ Object (also: #add_column)
- #add_image(name, data_field = nil, &block) ⇒ Object
- #add_section(section_name, collection_field, opts = {}) {|sec| ... } ⇒ Object
- #add_table(table_name, collection_field, opts = {}) {|tab| ... } ⇒ Object
- #add_text(name, data_field = nil, &block) ⇒ Object
- #all_images ⇒ Object
-
#initialize(opts) ⇒ Nestable
constructor
A new instance of Nestable.
- #set_source(data_item) ⇒ Object
- #wrap_with_ns(node) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Nestable
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/odf-report/nestable.rb', line 4 def initialize(opts) @name = opts[:name] @data_source = DataSource.new(opts) @fields = [] @texts = [] @tables = [] @sections = [] @images = [] end |
Instance Method Details
#add_field(name, data_field = nil, &block) ⇒ Object Also known as: add_column
22 23 24 25 |
# File 'lib/odf-report/nestable.rb', line 22 def add_field(name, data_field=nil, &block) opts = { name: name, data_field: data_field } @fields << Field.new(opts, &block) end |
#add_image(name, data_field = nil, &block) ⇒ Object
33 34 35 36 |
# File 'lib/odf-report/nestable.rb', line 33 def add_image(name, data_field=nil, &block) opts = {name: name, data_field: data_field} @images << Image.new(opts, &block) end |
#add_section(section_name, collection_field, opts = {}) {|sec| ... } ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/odf-report/nestable.rb', line 46 def add_section(section_name, collection_field, opts={}) opts.merge!(name: section_name, collection_field: collection_field) sec = Section.new(opts) @sections << sec yield(sec) end |
#add_table(table_name, collection_field, opts = {}) {|tab| ... } ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/odf-report/nestable.rb', line 38 def add_table(table_name, collection_field, opts={}) opts.merge!(name: table_name, collection_field: collection_field) tab = Table.new(opts) @tables << tab yield(tab) end |
#add_text(name, data_field = nil, &block) ⇒ Object
28 29 30 31 |
# File 'lib/odf-report/nestable.rb', line 28 def add_text(name, data_field=nil, &block) opts = {name: name, data_field: data_field} @texts << Text.new(opts, &block) end |
#all_images ⇒ Object
54 55 56 |
# File 'lib/odf-report/nestable.rb', line 54 def all_images (@images.map(&:files) + @sections.map(&:all_images) + @tables.map(&:all_images)).flatten end |
#set_source(data_item) ⇒ Object
17 18 19 20 |
# File 'lib/odf-report/nestable.rb', line 17 def set_source(data_item) @data_source.set_source(data_item) self end |
#wrap_with_ns(node) ⇒ Object
58 59 60 61 62 |
# File 'lib/odf-report/nestable.rb', line 58 def wrap_with_ns(node) <<-XML <root xmlns:draw="a" xmlns:xlink="b" xmlns:text="c" xmlns:table="d">#{node.to_xml}</root> XML end |