Class: OxmlMaker::Paragraph

Inherits:
Object
  • Object
show all
Defined in:
lib/oxml_maker/paragraph.rb

Overview

Represents a paragraph in an OXML document. It can be used to create structured text content within a Word document. The class is initialized with data that will be used to populate the paragraph.

Examples:

paragraph = Oxml::Paragraph.new(data: {text: "Hello, World!"})
puts paragraph.template
# Output: <w:p><w:r><w:t>Hello, World!</w:t></w:r></w:p>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Paragraph

Returns a new instance of Paragraph.

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/oxml_maker/paragraph.rb', line 16

def initialize(data = {})
  raise ArgumentError, "Data must be a Hash" unless data.is_a?(Hash)

  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/oxml_maker/paragraph.rb', line 14

def data
  @data
end

Instance Method Details

#templateObject



22
23
24
25
26
27
28
29
30
# File 'lib/oxml_maker/paragraph.rb', line 22

def template
  <<~XML
    <w:p>
      <w:r>
        <w:t>#{data[:text]}</w:t>
      </w:r>
    </w:p>
  XML
end