Class: Gitlab::Ci::Ansi2json::Line::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/ansi2json/line.rb

Overview

Line::Segment is a portion of a line that has its own style and text. Multiple segments make the line content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style:) ⇒ Segment

Returns a new instance of Segment.


14
15
16
17
# File 'lib/gitlab/ci/ansi2json/line.rb', line 14

def initialize(style:)
  @text = +''
  @style = style
end

Instance Attribute Details

#styleObject

Returns the value of attribute style


12
13
14
# File 'lib/gitlab/ci/ansi2json/line.rb', line 12

def style
  @style
end

#textObject

Returns the value of attribute text


12
13
14
# File 'lib/gitlab/ci/ansi2json/line.rb', line 12

def text
  @text
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/gitlab/ci/ansi2json/line.rb', line 19

def empty?
  text.empty?
end

#to_hObject


23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/ci/ansi2json/line.rb', line 23

def to_h
  # Without force encoding to UTF-8 we could get an error
  # when serializing the Hash to JSON.
  # Encoding::UndefinedConversionError:
  #   "\xE2" from ASCII-8BIT to UTF-8
  { text: text.force_encoding('UTF-8') }.tap do |result|
    result[:style] = style.to_s if style.set?
  end
end