Class: RRTF::GeometryNode

Inherits:
CommandNode show all
Defined in:
lib/rrtf/node/geometry_node.rb

Overview

This class represents a geometry object (shape or text box) within an RTF document.

Author:

  • Wesley Hileman

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from CommandNode

#prefix, #split, #suffix, #wrap

Attributes inherited from ContainerNode

#children

Attributes inherited from Node

#parent

Instance Method Summary collapse

Methods inherited from CommandNode

#apply, #column_break, #footnote, #image, #line_break, #link, #list, #paragraph, #section, #tab, #table

Methods inherited from ContainerNode

#[], #each, #first, #last, #size, #store

Methods inherited from Node

#is_root?, #next_node, #previous_node, #root

Constructor Details

#initialize(parent, properties = nil) ⇒ GeometryNode

Constructor for the GeometryNode class.

Parameters:

  • properties (Hash, GeometryProperties) (defaults to: nil)

    a hash or GeometryProperties object specifying the properties of the geometry object.

Since:

  • 1.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rrtf/node/geometry_node.rb', line 14

def initialize(parent, properties = nil)
  case properties
  when Hash
    @properties = GeometryProperties.new(properties)
  when GeometryProperties
    @properties = properties
  else
    RTFError.fire("Invalid geometry properties '#{properties}'.")
  end unless properties.nil?

  prefix = '{\shp{\*\shpinst'
  prefix << @properties.to_rtf unless properties.nil?

  super(parent, prefix, '}}', false, false)
end

Instance Attribute Details

#propertiesObject (readonly)

Since:

  • 1.0.0



8
9
10
# File 'lib/rrtf/node/geometry_node.rb', line 8

def properties
  @properties
end

Instance Method Details

#<<(text) ⇒ Object

Overrides the CommandNode#<< method to prevent text from being added to geometry objects directly. Calls CommandNode#paragraph instead.

Raises:

Since:

  • 1.0.0



61
62
63
# File 'lib/rrtf/node/geometry_node.rb', line 61

def <<(text)
  self.paragraph << text
end

#geometry(properties = nil) ⇒ Object

Overrides the CommandNode#geometry method to prevent geometry objects from being nested in other geometry objects.

Raises:

Since:

  • 1.0.0



53
54
55
# File 'lib/rrtf/node/geometry_node.rb', line 53

def geometry(properties = nil)
  RTFError.fire("Cannot place a geometry object inside of another.")
end

#to_rtfObject

Since:

  • 1.0.0



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rrtf/node/geometry_node.rb', line 30

def to_rtf
  text = StringIO.new

  text << @prefix

  unless self.size() == 0
    text << '{\shptxt'
    self.each do |entry|
       text << "\n"
       text << entry.to_rtf
    end # each
    text << '}'
  end # unless

  text << @suffix

  text.string
end