Class: TansParser::Selector
- Inherits:
-
Object
- Object
- TansParser::Selector
- 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. # => [Element, ...]
selector.dialogs # => [Element, ...]
selector.(text: "OK") # => Element or nil
Constant Summary collapse
- TOP_LEFT_CORNERS =
/[┌┏┎┍╭╔╓╒]/- BOTTOM_LEFT_CORNERS =
%w[└ ┗ ┖ ┕ ╰ ╚].freeze
- BOTTOM_RIGHT_CORNERS =
%w[┘ ┛ ┚ ┙ ╯ ╝].freeze
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#button(**filters) ⇒ Object
Convenience accessors (singular — return first element or nil).
-
#buttons(**filters) ⇒ Object
Convenience accessors (plural — return arrays).
- #checkbox(**filters) ⇒ Object
- #checkboxes(**filters) ⇒ Object
- #dialog(**filters) ⇒ Object
- #dialogs(**filters) ⇒ Object
-
#get_by_role(role, text: nil, checked: nil, disabled: nil) ⇒ Object
Find elements by role with optional filters.
-
#get_by_text(text) ⇒ Object
Find elements by visible text (partial match).
-
#initialize(state) ⇒ Selector
constructor
A new instance of Selector.
- #input(**filters) ⇒ Object
- #inputs(**filters) ⇒ Object
- #label(**filters) ⇒ Object
- #labels(**filters) ⇒ Object
- #menu(**filters) ⇒ Object
- #menus(**filters) ⇒ Object
- #progress_bar(**filters) ⇒ Object
- #progress_bars(**filters) ⇒ Object
- #statusbar(**filters) ⇒ Object
- #statusbars(**filters) ⇒ Object
- #tab(**filters) ⇒ Object
- #tabs(**filters) ⇒ Object
-
#within(element, &block) ⇒ Object
Scope subsequent searches to a specific element’s bounding box.
Constructor Details
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
20 21 22 |
# File 'lib/tans_parser/selector.rb', line 20 def elements @elements end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
20 21 22 |
# File 'lib/tans_parser/selector.rb', line 20 def state @state end |
Instance Method Details
#button(**filters) ⇒ Object
Convenience accessors (singular — return first element or nil)
81 82 83 |
# File 'lib/tans_parser/selector.rb', line 81 def (**filters) (**filters).first end |
#buttons(**filters) ⇒ Object
Convenience accessors (plural — return arrays)
44 45 46 |
# File 'lib/tans_parser/selector.rb', line 44 def (**filters) get_by_role(:button, **filters) end |
#checkbox(**filters) ⇒ Object
85 86 87 |
# File 'lib/tans_parser/selector.rb', line 85 def checkbox(**filters) checkboxes(**filters).first end |
#checkboxes(**filters) ⇒ Object
48 49 50 |
# File 'lib/tans_parser/selector.rb', line 48 def checkboxes(**filters) get_by_role(:checkbox, **filters) end |
#dialog(**filters) ⇒ Object
89 90 91 |
# File 'lib/tans_parser/selector.rb', line 89 def dialog(**filters) dialogs(**filters).first end |
#dialogs(**filters) ⇒ Object
52 53 54 |
# File 'lib/tans_parser/selector.rb', line 52 def dialogs(**filters) get_by_role(:dialog, **filters) end |
#get_by_role(role, text: nil, checked: nil, disabled: nil) ⇒ Object
Find elements by role with optional filters. rubocop:disable Metrics/CyclomaticComplexity
34 35 36 37 38 39 40 |
# File 'lib/tans_parser/selector.rb', line 34 def get_by_role(role, text: nil, checked: nil, disabled: nil) results = @elements.select { |e| e.role == role.to_sym } results = results.select { |e| e.text.to_s.include?(text.to_s) } if text results = results.select { |e| e.checked == checked } unless checked.nil? results = results.select { |e| e.disabled == disabled } unless disabled.nil? results end |
#get_by_text(text) ⇒ Object
Find elements by visible text (partial match).
28 29 30 |
# File 'lib/tans_parser/selector.rb', line 28 def get_by_text(text) @elements.select { |e| e.text&.include?(text) } end |
#input(**filters) ⇒ Object
93 94 95 |
# File 'lib/tans_parser/selector.rb', line 93 def input(**filters) inputs(**filters).first end |
#inputs(**filters) ⇒ Object
56 57 58 |
# File 'lib/tans_parser/selector.rb', line 56 def inputs(**filters) get_by_role(:input, **filters) end |
#label(**filters) ⇒ Object
97 98 99 |
# File 'lib/tans_parser/selector.rb', line 97 def label(**filters) labels(**filters).first end |
#labels(**filters) ⇒ Object
60 61 62 |
# File 'lib/tans_parser/selector.rb', line 60 def labels(**filters) get_by_role(:label, **filters) end |
#menu(**filters) ⇒ Object
101 102 103 |
# File 'lib/tans_parser/selector.rb', line 101 def (**filters) (**filters).first end |
#menus(**filters) ⇒ Object
64 65 66 |
# File 'lib/tans_parser/selector.rb', line 64 def (**filters) get_by_role(:menu, **filters) end |
#progress_bar(**filters) ⇒ Object
113 114 115 |
# File 'lib/tans_parser/selector.rb', line 113 def (**filters) (**filters).first end |
#progress_bars(**filters) ⇒ Object
76 77 78 |
# File 'lib/tans_parser/selector.rb', line 76 def (**filters) get_by_role(:progress, **filters) end |
#statusbar(**filters) ⇒ Object
109 110 111 |
# File 'lib/tans_parser/selector.rb', line 109 def (**filters) (**filters).first end |
#statusbars(**filters) ⇒ Object
72 73 74 |
# File 'lib/tans_parser/selector.rb', line 72 def (**filters) get_by_role(:statusbar, **filters) end |
#tab(**filters) ⇒ Object
105 106 107 |
# File 'lib/tans_parser/selector.rb', line 105 def tab(**filters) tabs(**filters).first end |
#tabs(**filters) ⇒ Object
68 69 70 |
# File 'lib/tans_parser/selector.rb', line 68 def tabs(**filters) get_by_role(:tab, **filters) end |
#within(element, &block) ⇒ Object
Scope subsequent searches to a specific element’s bounding box.
118 119 120 121 122 123 124 125 |
# File 'lib/tans_parser/selector.rb', line 118 def within(element, &block) scoped = ScopedSelector.new(self, element) if block yield scoped else scoped end end |