Class: Uniword::Hyperlink
- Inherits:
-
Object
- Object
- Uniword::Hyperlink
- Defined in:
- lib/uniword/hyperlink.rb
Overview
Hyperlink convenience wrapper for external and internal links.
This provides a simplified API over the underlying Wordprocessingml::Hyperlink model.
Instance Attribute Summary collapse
-
#anchor ⇒ String?
readonly
Anchor/bookmark name for internal links.
-
#text ⇒ String
readonly
Display text.
-
#tooltip ⇒ String?
readonly
Tooltip text.
-
#url ⇒ String?
readonly
URL for external links.
Instance Method Summary collapse
-
#external? ⇒ Boolean
True if this is an external URL link.
-
#initialize(url: nil, anchor: nil, text: nil, tooltip: nil) ⇒ Hyperlink
constructor
A new instance of Hyperlink.
-
#internal? ⇒ Boolean
True if this is an internal anchor link.
-
#to_h ⇒ Hash
Hash representation.
-
#to_model ⇒ Wordprocessingml::Hyperlink
Convert to the underlying Wordprocessingml::Hyperlink model.
Constructor Details
#initialize(url: nil, anchor: nil, text: nil, tooltip: nil) ⇒ Hyperlink
Returns a new instance of Hyperlink.
36 37 38 39 40 41 |
# File 'lib/uniword/hyperlink.rb', line 36 def initialize(url: nil, anchor: nil, text: nil, tooltip: nil) @url = url @anchor = anchor @text = text @tooltip = tooltip end |
Instance Attribute Details
#anchor ⇒ String? (readonly)
Returns Anchor/bookmark name for internal links.
24 25 26 |
# File 'lib/uniword/hyperlink.rb', line 24 def anchor @anchor end |
#text ⇒ String (readonly)
Returns Display text.
27 28 29 |
# File 'lib/uniword/hyperlink.rb', line 27 def text @text end |
#tooltip ⇒ String? (readonly)
Returns Tooltip text.
30 31 32 |
# File 'lib/uniword/hyperlink.rb', line 30 def tooltip @tooltip end |
#url ⇒ String? (readonly)
Returns URL for external links.
21 22 23 |
# File 'lib/uniword/hyperlink.rb', line 21 def url @url end |
Instance Method Details
#external? ⇒ Boolean
Returns True if this is an external URL link.
44 45 46 |
# File 'lib/uniword/hyperlink.rb', line 44 def external? !url.nil? end |
#internal? ⇒ Boolean
Returns True if this is an internal anchor link.
49 50 51 |
# File 'lib/uniword/hyperlink.rb', line 49 def internal? !anchor.nil? end |
#to_h ⇒ Hash
Returns Hash representation.
72 73 74 |
# File 'lib/uniword/hyperlink.rb', line 72 def to_h { url: url, anchor: anchor, text: text, tooltip: tooltip } end |
#to_model ⇒ Wordprocessingml::Hyperlink
Convert to the underlying Wordprocessingml::Hyperlink model
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/uniword/hyperlink.rb', line 56 def to_model model = Wordprocessingml::Hyperlink.new model.id = url if url model.anchor = anchor if anchor model.tooltip = tooltip if tooltip if text run = Wordprocessingml::Run.new run.text = Wordprocessingml::Text.new(content: text) model.runs << run end model end |