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

#confidenceObject

Returns the value of attribute confidence

Returns:

  • (Object)

    the current value of confidence



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

def confidence
  @confidence
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



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

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

#checked?Boolean

Returns:

  • (Boolean)


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

def checked?
  !!checked
end

#clickObject



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

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

#confident?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/tans_parser/element.rb', line 41

def confident?
  confidence.nil? || confidence >= 0.5
end

#disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  !!disabled
end

#press_key(key) ⇒ Object



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

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

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tans_parser/element.rb', line 45

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,
    confidence: confidence,
  }.compact
end

#type(text) ⇒ Object



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

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