Class: Uniword::CommentRange

Inherits:
Element
  • Object
show all
Defined in:
lib/uniword/comment_range.rb

Overview

Represents a comment range marker in a Word document.

Comments in Word documents are anchored to specific text ranges using commentRangeStart and commentRangeEnd markers. These markers define the beginning and end of the commented text.

In OOXML:

  • <w:commentRangeStart> marks the start of a commented range

  • <w:commentRangeEnd> marks the end of a commented range

  • <w:commentReference> provides the actual link to the comment

Examples:

Create comment range markers

range_start = Uniword::CommentRange.new(
  comment_id: "1",
  marker_type: :start
)
range_end = Uniword::CommentRange.new(
  comment_id: "1",
  marker_type: :end
)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

abstract!, abstract?

Constructor Details

#initialize(attributes = {}) ⇒ CommentRange

Initialize a comment range marker

Parameters:

  • attributes (Hash) (defaults to: {})

    Marker attributes

Options Hash (attributes):

  • :comment_id (String)

    Comment ID (required)

  • :marker_type (Symbol)

    Marker type (:start, :end, :reference)



49
50
51
52
# File 'lib/uniword/comment_range.rb', line 49

def initialize(attributes = {})
  @marker_type = attributes.delete(:marker_type) || :start
  super
end

Instance Attribute Details

#comment_idString

The ID of the associated comment

Returns:

  • (String)

    the current value of comment_id



29
30
31
# File 'lib/uniword/comment_range.rb', line 29

def comment_id
  @comment_id
end

#marker_typeObject

Type of marker (:start, :end, :reference)



29
30
31
# File 'lib/uniword/comment_range.rb', line 29

def marker_type
  @marker_type
end

Instance Method Details

#accept(visitor) ⇒ Object

Accept a visitor for the visitor pattern

Parameters:

  • visitor (Object)

    The visitor object

Returns:

  • (Object)

    The result of the visit operation



58
59
60
# File 'lib/uniword/comment_range.rb', line 58

def accept(visitor)
  visitor.visit_comment_range(self)
end

#end?Boolean

Check if this is an end marker

Returns:

  • (Boolean)

    true if end marker



72
73
74
# File 'lib/uniword/comment_range.rb', line 72

def end?
  marker_type == :end
end

#inspectString

Provide detailed inspection for debugging

Returns:

  • (String)

    A readable representation of the comment range



109
110
111
# File 'lib/uniword/comment_range.rb', line 109

def inspect
  "#<Uniword::CommentRange type=#{marker_type.inspect} comment_id=#{comment_id.inspect}>"
end

#reference?Boolean

Check if this is a reference marker

Returns:

  • (Boolean)

    true if reference marker



79
80
81
# File 'lib/uniword/comment_range.rb', line 79

def reference?
  marker_type == :reference
end

#start?Boolean

Check if this is a start marker

Returns:

  • (Boolean)

    true if start marker



65
66
67
# File 'lib/uniword/comment_range.rb', line 65

def start?
  marker_type == :start
end

#valid?Boolean

Check if the comment range is valid

Returns:

  • (Boolean)

    true if valid, false otherwise



86
87
88
# File 'lib/uniword/comment_range.rb', line 86

def valid?
  required_attributes_valid?
end

#xml_element_nameString

Get the XML element name based on marker type

Returns:

  • (String)

    The XML element name



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/uniword/comment_range.rb', line 93

def xml_element_name
  case marker_type
  when :start
    "commentRangeStart"
  when :end
    "commentRangeEnd"
  when :reference
    "commentReference"
  else
    raise ArgumentError, "Invalid marker type: #{marker_type}"
  end
end