Class: Uniword::Docx::CustomXmlItem
- Inherits:
-
Object
- Object
- Uniword::Docx::CustomXmlItem
- Defined in:
- lib/uniword/docx/custom_xml_item.rb
Overview
One customXml data item (customXml/itemN.xml) with its optional properties part and relationships part.
Replaces the former +{ index:, xml_content:, props_xml:,
rels_xml: }+ hash entries in custom_xml_items.
Instance Attribute Summary collapse
-
#index ⇒ Integer
Item number (customXml/item%
d.xml). -
#props_xml ⇒ String?
Raw XML of the itemProps part.
-
#rels_xml ⇒ String?
Raw XML of the item relationships part.
-
#xml_content ⇒ String
Raw XML of the item part.
Class Method Summary collapse
-
.wrap(value) ⇒ CustomXmlItem
Normalize a legacy hash entry (or an existing CustomXmlItem) into a CustomXmlItem.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Hash-style read compatibility.
-
#initialize(index:, xml_content:, props_xml: nil, rels_xml: nil) ⇒ CustomXmlItem
constructor
A new instance of CustomXmlItem.
-
#package_paths ⇒ Array<String>
Package paths this item emits (item part plus its properties part when present).
-
#path ⇒ String
Package path of the item part.
-
#props_path ⇒ String?
Package path of the properties part.
Constructor Details
#initialize(index:, xml_content:, props_xml: nil, rels_xml: nil) ⇒ CustomXmlItem
Returns a new instance of CustomXmlItem.
27 28 29 30 31 32 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 27 def initialize(index:, xml_content:, props_xml: nil, rels_xml: nil) @index = index @xml_content = xml_content @props_xml = props_xml @rels_xml = rels_xml end |
Instance Attribute Details
#index ⇒ Integer
Returns item number (customXml/item%
12 13 14 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 12 def index @index end |
#props_xml ⇒ String?
Returns raw XML of the itemProps part.
18 19 20 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 18 def props_xml @props_xml end |
#rels_xml ⇒ String?
Returns raw XML of the item relationships part.
21 22 23 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 21 def rels_xml @rels_xml end |
#xml_content ⇒ String
Returns raw XML of the item part.
15 16 17 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 15 def xml_content @xml_content end |
Class Method Details
.wrap(value) ⇒ CustomXmlItem
Normalize a legacy hash entry (or an existing CustomXmlItem) into a CustomXmlItem.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 39 def self.wrap(value) return value if value.is_a?(CustomXmlItem) new( index: value[:index], xml_content: value[:xml_content], props_xml: value[:props_xml], rels_xml: value[:rels_xml], ) end |
Instance Method Details
#[](key) ⇒ Object?
Hash-style read compatibility.
81 82 83 84 85 86 87 88 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 81 def [](key) case key.to_sym when :index then index when :xml_content then xml_content when :props_xml then props_xml when :rels_xml then rels_xml end end |
#package_paths ⇒ Array<String>
Package paths this item emits (item part plus its properties part when present).
72 73 74 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 72 def package_paths [path, props_path].compact end |
#path ⇒ String
Package path of the item part.
53 54 55 56 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 53 def path Ooxml::PartRegistry.find_by_key(:custom_xml_item) .path_for(index: index) end |
#props_path ⇒ String?
Package path of the properties part.
61 62 63 64 65 66 |
# File 'lib/uniword/docx/custom_xml_item.rb', line 61 def props_path return nil unless props_xml Ooxml::PartRegistry.find_by_key(:custom_xml_item_props) .path_for(index: index) end |