Class: DocxReport::ContentFile
- Inherits:
-
Object
- Object
- DocxReport::ContentFile
- Defined in:
- lib/docx_report/content_file.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#new_rels ⇒ Object
readonly
Returns the value of attribute new_rels.
-
#rels_name ⇒ Object
readonly
Returns the value of attribute rels_name.
-
#rels_xml ⇒ Object
readonly
Returns the value of attribute rels_xml.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#initialize(name, zip) ⇒ ContentFile
constructor
A new instance of ContentFile.
- #new_rels_xml ⇒ Object
- #new_uniqe_id ⇒ Object
- #rels_has_items? ⇒ Boolean
Constructor Details
#initialize(name, zip) ⇒ ContentFile
Returns a new instance of ContentFile.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/docx_report/content_file.rb', line 5 def initialize(name, zip) @name = name @xml = Nokogiri::XML(zip.read(name)) @rels_name = "#{name.sub '/', '/_rels/'}.rels" @new_rels = false @rels_xml = Nokogiri::XML(if zip.entries.any? { |r| r.name == @rels_name } zip.read(@rels_name) else new_rels_xml end) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/docx_report/content_file.rb', line 3 def name @name end |
#new_rels ⇒ Object (readonly)
Returns the value of attribute new_rels.
3 4 5 |
# File 'lib/docx_report/content_file.rb', line 3 def new_rels @new_rels end |
#rels_name ⇒ Object (readonly)
Returns the value of attribute rels_name.
3 4 5 |
# File 'lib/docx_report/content_file.rb', line 3 def rels_name @rels_name end |
#rels_xml ⇒ Object (readonly)
Returns the value of attribute rels_xml.
3 4 5 |
# File 'lib/docx_report/content_file.rb', line 3 def rels_xml @rels_xml end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
3 4 5 |
# File 'lib/docx_report/content_file.rb', line 3 def xml @xml end |
Instance Method Details
#new_rels_xml ⇒ Object
23 24 25 26 27 28 |
# File 'lib/docx_report/content_file.rb', line 23 def new_rels_xml @new_rels = true '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships'\ 'xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'\ '</Relationships>' end |
#new_uniqe_id ⇒ Object
17 18 19 20 21 |
# File 'lib/docx_report/content_file.rb', line 17 def new_uniqe_id (@rels_xml.xpath('//*[@Id]').map do |e| e[:Id][3..-1].to_i if e.name == 'Relationship' end.compact.max || 0) + 1 end |
#rels_has_items? ⇒ Boolean
30 31 32 |
# File 'lib/docx_report/content_file.rb', line 30 def rels_has_items? @rels_xml.xpath('//*[@Id]').any? end |