Class: TansParser::Element

Inherits:
Struct
  • Object
show all
Defined in:
lib/tans_parser/element.rb

Overview

Describes a recognized UI element on the terminal screen.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bgObject

Returns the value of attribute bg

Returns:

  • (Object)

    the current value of bg



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def bg
  @bg
end

#checkedObject

Returns the value of attribute checked

Returns:

  • (Object)

    the current value of checked



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def checked
  @checked
end

#colObject

Returns the value of attribute col

Returns:

  • (Object)

    the current value of col



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def col
  @col
end

#disabledObject

Returns the value of attribute disabled

Returns:

  • (Object)

    the current value of disabled



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def disabled
  @disabled
end

#fgObject

Returns the value of attribute fg

Returns:

  • (Object)

    the current value of fg



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def fg
  @fg
end

#focusedObject

Returns the value of attribute focused

Returns:

  • (Object)

    the current value of focused



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def focused
  @focused
end

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def height
  @height
end

#roleObject

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def role
  @role
end

#rowObject

Returns the value of attribute row

Returns:

  • (Object)

    the current value of row



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def row
  @row
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def text
  @text
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



5
6
7
# File 'lib/tans_parser/element.rb', line 5

def width
  @width
end

Instance Method Details

#boundsObject



24
25
26
# File 'lib/tans_parser/element.rb', line 24

def bounds
  { row: row, col: col, width: width, height: height }
end

#checked?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/tans_parser/element.rb', line 16

def checked?
  !!checked
end

#clickObject



28
29
30
# File 'lib/tans_parser/element.rb', line 28

def click
  { action: :click, target: self, row: row, col: col + (width / 2) }
end

#disabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/tans_parser/element.rb', line 20

def disabled?
  !!disabled
end

#press_key(key) ⇒ Object



36
37
38
# File 'lib/tans_parser/element.rb', line 36

def press_key(key)
  { action: :press_key, target: self, key: key }
end

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tans_parser/element.rb', line 40

def to_h
  {
    role: role,
    text: text,
    row: row, col: col,
    width: width, height: height,
    checked: checked,
    focused: focused,
    fg: fg, bg: bg,
    disabled: disabled,
  }.compact
end

#type(text) ⇒ Object



32
33
34
# File 'lib/tans_parser/element.rb', line 32

def type(text)
  { action: :type, target: self, row: row, col: col + (width / 2), text: text }
end