Class: Uniword::Bookmark
- Inherits:
-
Object
- Object
- Uniword::Bookmark
- Defined in:
- lib/uniword/bookmark.rb
Overview
Represents a bookmark or anchor in a document.
Responsibility: Store bookmark metadata for creating internal links and anchors within a document. Bookmarks allow users to navigate to specific locations within a document.
A bookmark consists of:
-
A name that uniquely identifies it
-
An optional target element reference
Instance Attribute Summary collapse
-
#bookmark_id ⇒ String?
The OOXML bookmark ID for round-trip preservation.
-
#name ⇒ String
The unique name/identifier for this bookmark.
-
#target_element ⇒ Element?
The target element this bookmark references.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality with another bookmark.
-
#anchor_name ⇒ String
Generate HTML anchor name.
-
#hash ⇒ Integer
Generate hash code for bookmark.
-
#initialize(name:, target_element: nil, bookmark_id: nil) ⇒ Bookmark
constructor
Initialize a new Bookmark.
-
#target? ⇒ Boolean
Check if bookmark has a target element.
-
#to_h ⇒ Hash
Convert to hash representation.
Constructor Details
#initialize(name:, target_element: nil, bookmark_id: nil) ⇒ Bookmark
Initialize a new Bookmark.
47 48 49 50 51 |
# File 'lib/uniword/bookmark.rb', line 47 def initialize(name:, target_element: nil, bookmark_id: nil) @name = name @target_element = target_element @bookmark_id = bookmark_id end |
Instance Attribute Details
#bookmark_id ⇒ String?
Returns The OOXML bookmark ID for round-trip preservation.
31 32 33 |
# File 'lib/uniword/bookmark.rb', line 31 def bookmark_id @bookmark_id end |
#name ⇒ String
Returns The unique name/identifier for this bookmark.
25 26 27 |
# File 'lib/uniword/bookmark.rb', line 25 def name @name end |
#target_element ⇒ Element?
Returns The target element this bookmark references.
28 29 30 |
# File 'lib/uniword/bookmark.rb', line 28 def target_element @target_element end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality with another bookmark.
88 89 90 91 92 |
# File 'lib/uniword/bookmark.rb', line 88 def ==(other) return false unless other.is_a?(Bookmark) @name == other.name end |
#anchor_name ⇒ String
Generate HTML anchor name.
Sanitizes the bookmark name for use in HTML anchors.
69 70 71 |
# File 'lib/uniword/bookmark.rb', line 69 def anchor_name @name.to_s.downcase.gsub(/[^a-z0-9_-]/, "_") end |
#hash ⇒ Integer
Generate hash code for bookmark.
99 100 101 |
# File 'lib/uniword/bookmark.rb', line 99 def hash @name.hash end |
#target? ⇒ Boolean
Check if bookmark has a target element.
56 57 58 |
# File 'lib/uniword/bookmark.rb', line 56 def target? !@target_element.nil? end |
#to_h ⇒ Hash
Convert to hash representation.
76 77 78 79 80 81 82 |
# File 'lib/uniword/bookmark.rb', line 76 def to_h { name: @name, target_element: @target_element, bookmark_id: @bookmark_id, } end |