Module: ODFWriter::Nested

Included in:
Section, Table
Defined in:
lib/odf_writer/nested.rb

Overview

Nested: provide data to nestable items

Instance Method Summary collapse

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, options={}, &block)
  options.merge!(:name => name)
  @bookmarks << Bookmark.new(options, &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, options={}, &block)
  options.merge!(:name => name)
  @fields << Field.new(options, &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, options={}, &block)
  options.merge!(:name => name)
  @images << Image.new(options, &block)
end

#add_section(name, options = {}) {|sec| ... } ⇒ Object

def

Yields:

  • (sec)


59
60
61
62
63
64
# File 'lib/odf_writer/nested.rb', line 59

def add_section(name, options={})
  options.merge!(:name => name)
  sec = Section.new(options)
  @sections << sec
  yield(sec)
end

#add_table(name, options = {}) {|tab| ... } ⇒ Object

def

Yields:

  • (tab)


52
53
54
55
56
57
# File 'lib/odf_writer/nested.rb', line 52

def add_table(name, options={})
  options.merge!(:name => name)
  tab = Table.new(options)
  @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, options={}, &block)
  options.merge!(:name => name)
  @texts << Text.new(options, &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, options={})
  
  tree.to_h.each do |key, names|
    case key
    when :fields
      names.each do |name|
        add_field(name, options)
      end #def
    when :texts
      names.each do |name|
        add_text(name, options)
      end #def
    when :bookmarks
      names.each do |name|
        add_bookmark(name, options)
      end #def
    when :images
      names.each do |name|
        add_image(name, options)
      end #def
    when :tables
      names.each do |name, table_tree|
        add_table(name, options){|table| table.populate(table_tree, options)}
      end #def
    when :sections
      names.each do |name, section_tree|
        add_section(name, options){|section| section.populate(section_tree, options)}
      end #def
    end #case
  end #each
end