Class: TTYtest::Capture

Inherits:
Object
  • Object
show all
Includes:
Matchers
Defined in:
lib/ttytest/capture.rb

Constant Summary

Constants included from Matchers

Matchers::METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Matchers

#assert_cursor_position, #assert_row

Constructor Details

#initialize(contents, cursor_x: 0, cursor_y: 0, cursor_visible: true) ⇒ Capture

Returns a new instance of Capture.



7
8
9
10
11
12
13
14
# File 'lib/ttytest/capture.rb', line 7

def initialize(contents, cursor_x: 0, cursor_y: 0, cursor_visible: true)
  @rows = (contents+"\nEND").split("\n")[0...-1].map do |row|
    row || ""
  end
  @cursor_x = cursor_x
  @cursor_y = cursor_y
  @cursor_visible = cursor_visible
end

Instance Attribute Details

#cursor_visibleObject (readonly)

Returns the value of attribute cursor_visible.



5
6
7
# File 'lib/ttytest/capture.rb', line 5

def cursor_visible
  @cursor_visible
end

#cursor_xObject (readonly)

Returns the value of attribute cursor_x.



5
6
7
# File 'lib/ttytest/capture.rb', line 5

def cursor_x
  @cursor_x
end

#cursor_yObject (readonly)

Returns the value of attribute cursor_y.



5
6
7
# File 'lib/ttytest/capture.rb', line 5

def cursor_y
  @cursor_y
end

Instance Method Details

#captureObject



28
29
30
# File 'lib/ttytest/capture.rb', line 28

def capture
  self
end

#cursor_positionObject



16
17
18
# File 'lib/ttytest/capture.rb', line 16

def cursor_position
  [@cursor_x, @cursor_y]
end

#row(row) ⇒ Object



24
25
26
# File 'lib/ttytest/capture.rb', line 24

def row(row)
  rows[row]
end

#rowsObject



20
21
22
# File 'lib/ttytest/capture.rb', line 20

def rows
  @rows
end

#to_sObject



32
33
34
# File 'lib/ttytest/capture.rb', line 32

def to_s
  rows.join("\n")
end