Class: Cabriolet::Models::HLPLine
- Inherits:
-
Object
- Object
- Cabriolet::Models::HLPLine
- Defined in:
- lib/cabriolet/models/hlp_file.rb
Overview
QuickHelp topic line model
Represents a single line within a topic, including text, styles, and links.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#apply_link(start_index, end_index, link) ⇒ void
Apply link to a range of characters.
-
#apply_style(start_index, end_index, style) ⇒ void
Apply style to a range of characters.
-
#initialize(text = "") ⇒ HLPLine
constructor
Initialize a topic line.
-
#length ⇒ Integer
Get line length in characters.
Constructor Details
#initialize(text = "") ⇒ HLPLine
Initialize a topic line
58 59 60 61 |
# File 'lib/cabriolet/models/hlp_file.rb', line 58 def initialize(text = "") @text = text @attributes = Array.new(text.length) { TextAttribute.new } end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
53 54 55 |
# File 'lib/cabriolet/models/hlp_file.rb', line 53 def attributes @attributes end |
#text ⇒ Object
Returns the value of attribute text.
53 54 55 |
# File 'lib/cabriolet/models/hlp_file.rb', line 53 def text @text end |
Instance Method Details
#apply_link(start_index, end_index, link) ⇒ void
This method returns an undefined value.
Apply link to a range of characters
88 89 90 91 92 93 94 95 96 |
# File 'lib/cabriolet/models/hlp_file.rb', line 88 def apply_link(start_index, end_index, link) # Convert from 1-based to 0-based indexing start_idx = start_index - 1 end_idx = end_index - 1 (start_idx..end_idx).each do |i| @attributes[i].link = link if i >= 0 && i < @attributes.length end end |
#apply_style(start_index, end_index, style) ⇒ void
This method returns an undefined value.
Apply style to a range of characters
76 77 78 79 80 |
# File 'lib/cabriolet/models/hlp_file.rb', line 76 def apply_style(start_index, end_index, style) (start_index..end_index).each do |i| @attributes[i].style = style if i < @attributes.length end end |
#length ⇒ Integer
Get line length in characters
66 67 68 |
# File 'lib/cabriolet/models/hlp_file.rb', line 66 def length @text.length end |