Class: Cabriolet::Models::HLPLine

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(text = "") ⇒ HLPLine

Initialize a topic line

Parameters:

  • text (String) (defaults to: "")

    plain text content



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

#attributesObject

Returns the value of attribute attributes.



53
54
55
# File 'lib/cabriolet/models/hlp_file.rb', line 53

def attributes
  @attributes
end

#textObject

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

This method returns an undefined value.

Apply link to a range of characters

Parameters:

  • start_index (Integer)

    start position (1-based, as per format)

  • end_index (Integer)

    end position (1-based, inclusive)

  • link (String)

    link target (context string or topic index)



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

Parameters:

  • start_index (Integer)

    start position (0-based)

  • end_index (Integer)

    end position (0-based, inclusive)

  • style (Integer)

    style flags



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

#lengthInteger

Get line length in characters

Returns:

  • (Integer)

    character count



66
67
68
# File 'lib/cabriolet/models/hlp_file.rb', line 66

def length
  @text.length
end