Class: Rubyword::Document

Inherits:
Object
  • Object
show all
Includes:
Writer
Defined in:
lib/rubyword/document.rb

Constant Summary

Constants included from Writer

Writer::DocumentBaseFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Writer

#save, #write_header_and_footer

Constructor Details

#initialize(options = {}, &block) ⇒ Document

Returns a new instance of Document.



17
18
19
20
21
22
23
24
# File 'lib/rubyword/document.rb', line 17

def initialize(options={}, &block)
  @sections, @toc, @init_rid, @doc_info = [], {}, 7, {}
  @relation_rids = []
  @content_types = []
  @rels_documents = []
  @images = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#content_typesObject

Returns the value of attribute content_types.



7
8
9
# File 'lib/rubyword/document.rb', line 7

def content_types
  @content_types
end

#doc_infoObject

Returns the value of attribute doc_info.



9
10
11
# File 'lib/rubyword/document.rb', line 9

def doc_info
  @doc_info
end

Returns the value of attribute footer.



8
9
10
# File 'lib/rubyword/document.rb', line 8

def footer
  @footer
end

#headerObject

Returns the value of attribute header.



8
9
10
# File 'lib/rubyword/document.rb', line 8

def header
  @header
end

#imagesObject

Returns the value of attribute images.



7
8
9
# File 'lib/rubyword/document.rb', line 7

def images
  @images
end

#init_ridObject

Returns the value of attribute init_rid.



6
7
8
# File 'lib/rubyword/document.rb', line 6

def init_rid
  @init_rid
end

#relation_ridsObject

Returns the value of attribute relation_rids.



7
8
9
# File 'lib/rubyword/document.rb', line 7

def relation_rids
  @relation_rids
end

#rels_documentsObject

Returns the value of attribute rels_documents.



7
8
9
# File 'lib/rubyword/document.rb', line 7

def rels_documents
  @rels_documents
end

#sectionsObject

Returns the value of attribute sections.



6
7
8
# File 'lib/rubyword/document.rb', line 6

def sections
  @sections
end

#tocObject

Returns the value of attribute toc.



9
10
11
# File 'lib/rubyword/document.rb', line 9

def toc
  @toc
end

Class Method Details

.generate(filename, options = {}, &block) ⇒ Object



12
13
14
15
# File 'lib/rubyword/document.rb', line 12

def self.generate(filename, options = {}, &block)
  rubyword = new(options, &block)
  rubyword.save(filename)
end

Instance Method Details



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rubyword/document.rb', line 56

def add_footer(text=nil, options={})
  @footer = {
    id: 1,
    text: text,
    rid: self.init_rid,
    text_align: options[:align] || 'center',
    nums_type: options[:nums_type],
    type: 'footer'
  }
  self.content_types << {
    "/word/footer1.xml" => "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"
  }
  self.rels_documents << {
    Id: "rId#{self.init_rid}", 
    Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
    Target: "footer1.xml"
  }
  self.init_rid = self.init_rid + 1
end

#add_header(text, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubyword/document.rb', line 37

def add_header(text, options={})
  @header = {
    id: 1,
    text: text,
    rid: self.init_rid,
    text_align: options[:align] || 'center',
    type: 'header'
  }
  self.content_types << {
    "/word/header1.xml" => "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"
  }
  self.rels_documents << {
    Id: "rId#{self.init_rid}", 
    Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", 
    Target: "header1.xml"
  }
  self.init_rid = self.init_rid + 1
end

#information(options = {}) ⇒ Object



76
77
78
# File 'lib/rubyword/document.rb', line 76

def information(options={})
  @doc_info = options
end

#section(style = nil, &block) ⇒ Object



26
27
28
29
30
# File 'lib/rubyword/document.rb', line 26

def section(style=nil, &block)
  @section = Element::Section.new(@sections.count + 1, style, self)
  self.sections << @section
  @section.instance_eval(&block) if block_given?
end

#title_directory(option = {}) ⇒ Object



32
33
34
35
# File 'lib/rubyword/document.rb', line 32

def title_directory(option= {})
  @toc.merge!(open: true)
  @toc.merge!(option)
end