Class: Uniword::Docx::CustomXmlItem

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, xml_content:, props_xml: nil, rels_xml: nil) ⇒ CustomXmlItem

Returns a new instance of CustomXmlItem.

Parameters:

  • index (Integer)

    item number

  • xml_content (String)

    raw item XML

  • props_xml (String, nil) (defaults to: nil)

    raw itemProps XML

  • rels_xml (String, nil) (defaults to: nil)

    raw item relationships XML



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

#indexInteger

Returns item number (customXml/item%d.xml).

Returns:

  • (Integer)

    item number (customXml/item%d.xml)



12
13
14
# File 'lib/uniword/docx/custom_xml_item.rb', line 12

def index
  @index
end

#props_xmlString?

Returns raw XML of the itemProps part.

Returns:

  • (String, nil)

    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_xmlString?

Returns raw XML of the item relationships part.

Returns:

  • (String, nil)

    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_contentString

Returns raw XML of the item part.

Returns:

  • (String)

    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.

Parameters:

Returns:



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.

Parameters:

  • key (Symbol, String)

    one of :index, :xml_content, :props_xml, :rels_xml

Returns:

  • (Object, nil)


73
74
75
76
77
78
79
80
# File 'lib/uniword/docx/custom_xml_item.rb', line 73

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

#pathString

Package path of the item part.

Returns:

  • (String)

    e.g. "customXml/item1.xml"



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_pathString?

Package path of the properties part.

Returns:

  • (String, nil)

    e.g. "customXml/itemProps1.xml"



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