Class: Uniword::HeadersFooters::Manager
- Inherits:
-
Object
- Object
- Uniword::HeadersFooters::Manager
- Defined in:
- lib/uniword/headers_footers/manager.rb
Overview
Manages headers and footers for a document.
Provides CRUD operations for headers and footers with support for default, first-page, and even-page types.
Constant Summary collapse
- TYPES =
%w[default first even].freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#add_footer(text, type: "default") ⇒ Uniword::Footer
Add a footer to the document.
-
#add_header(text, type: "default") ⇒ Uniword::Header
Add a header to the document.
-
#clear_all ⇒ void
Clear all headers and footers.
-
#initialize(document) ⇒ Manager
constructor
A new instance of Manager.
-
#list_footers ⇒ Array<Hash>
List all footers in the document.
-
#list_headers ⇒ Array<Hash>
List all headers in the document.
-
#remove_footers(type:) ⇒ Integer
Remove footers by type.
-
#remove_headers(type:) ⇒ Integer
Remove headers by type.
Constructor Details
#initialize(document) ⇒ Manager
Returns a new instance of Manager.
21 22 23 |
# File 'lib/uniword/headers_footers/manager.rb', line 21 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
19 20 21 |
# File 'lib/uniword/headers_footers/manager.rb', line 19 def document @document end |
Instance Method Details
#add_footer(text, type: "default") ⇒ Uniword::Footer
Add a footer to the document.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/uniword/headers_footers/manager.rb', line 76 def (text, type: "default") validate_type(type) = Uniword::Footer.new(type: type) add_text_to(, text) document. ||= [] document. << end |
#add_header(text, type: "default") ⇒ Uniword::Header
Add a header to the document.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/uniword/headers_footers/manager.rb', line 59 def add_header(text, type: "default") validate_type(type) header = Uniword::Header.new(type: type) add_text_to(header, text) document.headers ||= [] document.headers << header header end |
#clear_all ⇒ void
This method returns an undefined value.
Clear all headers and footers.
114 115 116 117 |
# File 'lib/uniword/headers_footers/manager.rb', line 114 def clear_all document.headers = [] document. = [] end |
#list_footers ⇒ Array<Hash>
List all footers in the document.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/uniword/headers_footers/manager.rb', line 42 def = document. || [] .map do |f| { type: f.type, text: extract_text(f), empty: f.empty?, } end end |
#list_headers ⇒ Array<Hash>
List all headers in the document.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/uniword/headers_footers/manager.rb', line 28 def list_headers headers = document.headers || [] headers.map do |h| { type: h.type, text: extract_text(h), empty: h.empty?, } end end |
#remove_footers(type:) ⇒ Integer
Remove footers by type.
103 104 105 106 107 108 109 |
# File 'lib/uniword/headers_footers/manager.rb', line 103 def (type:) return 0 unless document. before = document..size document. = document..reject { |f| f.type == type } before - document..size end |
#remove_headers(type:) ⇒ Integer
Remove headers by type.
91 92 93 94 95 96 97 |
# File 'lib/uniword/headers_footers/manager.rb', line 91 def remove_headers(type:) return 0 unless document.headers before = document.headers.size document.headers = document.headers.reject { |h| h.type == type } before - document.headers.size end |