Module: ODFWriter::Nested
Overview
Nested: provide data to nestable items
Instance Method Summary collapse
-
#add_bookmark(name, options = {}, &block) ⇒ Object
def.
- #add_field(name, options = {}, &block) ⇒ Object (also: #add_column)
-
#add_image(name, options = {}, &block) ⇒ Object
def.
-
#add_section(name, options = {}) {|sec| ... } ⇒ Object
def.
-
#add_table(name, options = {}) {|tab| ... } ⇒ Object
def.
- #add_text(name, options = {}, &block) ⇒ Object
-
#items(item, field, procedure) ⇒ Object
items: get item collection form item.
-
#populate(tree, options = {}) ⇒ Object
populate.
Instance Method Details
#add_bookmark(name, options = {}, &block) ⇒ Object
def
42 43 44 45 |
# File 'lib/odf_writer/nested.rb', line 42 def add_bookmark(name, ={}, &block) .merge!(:name => name) @bookmarks << Bookmark.new(, &block) end |
#add_field(name, options = {}, &block) ⇒ Object Also known as: add_column
31 32 33 34 |
# File 'lib/odf_writer/nested.rb', line 31 def add_field(name, ={}, &block) .merge!(:name => name) @fields << Field.new(, &block) end |
#add_image(name, options = {}, &block) ⇒ Object
def
47 48 49 50 |
# File 'lib/odf_writer/nested.rb', line 47 def add_image(name, ={}, &block) .merge!(:name => name) @images << Image.new(, &block) end |
#add_section(name, options = {}) {|sec| ... } ⇒ Object
def
59 60 61 62 63 64 |
# File 'lib/odf_writer/nested.rb', line 59 def add_section(name, ={}) .merge!(:name => name) sec = Section.new() @sections << sec yield(sec) end |
#add_table(name, options = {}) {|tab| ... } ⇒ Object
def
52 53 54 55 56 57 |
# File 'lib/odf_writer/nested.rb', line 52 def add_table(name, ={}) .merge!(:name => name) tab = Table.new() @tables << tab yield(tab) end |
#add_text(name, options = {}, &block) ⇒ Object
37 38 39 40 |
# File 'lib/odf_writer/nested.rb', line 37 def add_text(name, ={}, &block) .merge!(:name => name) @texts << Text.new(, &block) end |
#items(item, field, procedure) ⇒ Object
items: get item collection form item
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/odf_writer/nested.rb', line 104 def items(item, field, procedure) #################################################################################### # call proc before other alternatives #################################################################################### return arrify(procedure.call(item, field)) if procedure #################################################################################### # item class dependend call #################################################################################### return arrify(hash_value(item, field)) if item.is_a?(Hash) #################################################################################### # field class dependend call #################################################################################### case field when String, Symbol if item.respond_to?(field.to_s.to_sym) arrify(item.send(field.to_s.to_sym)) elsif item.respond_to?(field.downcase.to_sym) arrify(item.send(field.downcase.to_sym)) else [] end else [] end #case end |
#populate(tree, options = {}) ⇒ Object
populate
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/odf_writer/nested.rb', line 69 def populate(tree, ={}) tree.to_h.each do |key, names| case key when :fields names.each do |name| add_field(name, ) end #def when :texts names.each do |name| add_text(name, ) end #def when :bookmarks names.each do |name| add_bookmark(name, ) end #def when :images names.each do |name| add_image(name, ) end #def when :tables names.each do |name, table_tree| add_table(name, ){|table| table.populate(table_tree, )} end #def when :sections names.each do |name, section_tree| add_section(name, ){|section| section.populate(section_tree, )} end #def end #case end #each end |