Class: TansParser::Selector

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

Overview

Scans terminal state for recognized UI elements.

selector = Selector.new(state)
selector.get_by_text("OK")       # => [Element, ...]
selector.get_by_role(:button)    # => [Element, ...]
selector.buttons                 # => [Element, ...]
selector.dialogs                 # => [Element, ...]

Constant Summary collapse

TOP_LEFT_CORNERS =
/[┌┏┎┍]/
BOTTOM_LEFT_CORNERS =
%w[     ].freeze
BOTTOM_RIGHT_CORNERS =
%w[     ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Selector

Returns a new instance of Selector.



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

def initialize(state)
  @state = state.is_a?(State) ? state : State.new(state)
  @elements = scan
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#buttonsObject

Convenience accessors



35
36
37
# File 'lib/tans_parser/selector.rb', line 35

def buttons
  get_by_role(:button)
end

#checkboxesObject



39
40
41
# File 'lib/tans_parser/selector.rb', line 39

def checkboxes
  get_by_role(:checkbox)
end

#dialogsObject



43
44
45
# File 'lib/tans_parser/selector.rb', line 43

def dialogs
  get_by_role(:dialog)
end

#get_by_role(role) ⇒ Object

Find elements by role.



30
31
32
# File 'lib/tans_parser/selector.rb', line 30

def get_by_role(role)
  @elements.select { |e| e.role == role.to_sym }
end

#get_by_text(text) ⇒ Object

Find elements by visible text (partial match).



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

def get_by_text(text)
  @elements.select { |e| e.text&.include?(text) }
end

#progress_barsObject



51
52
53
# File 'lib/tans_parser/selector.rb', line 51

def progress_bars
  get_by_role(:progress)
end

#statusbarsObject



47
48
49
# File 'lib/tans_parser/selector.rb', line 47

def statusbars
  get_by_role(:statusbar)
end