Class: TansParser::ScopedSelector
- Inherits:
-
Object
- Object
- TansParser::ScopedSelector
- Defined in:
- lib/tans_parser/scoped_selector.rb
Overview
Scoped view of a terminal screen restricted to an element’s bounding box. Created by Selector#within(element).
selector.within(dialog) do |scope|
scope. # only buttons inside the dialog
scope.find_text("OK")
end
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
Instance Method Summary collapse
-
#button(**filters) ⇒ Object
Convenience singular accessors.
-
#buttons(**filters) ⇒ Object
Convenience plural accessors.
- #checkbox(**filters) ⇒ Object
- #checkboxes(**filters) ⇒ Object
- #dialog(**filters) ⇒ Object
- #dialogs(**filters) ⇒ Object
-
#find_text(pattern, match: :partial) ⇒ Object
Search for text, scoped to the bounding box.
-
#get_by_role(role, text: nil, checked: nil, disabled: nil) ⇒ Object
Find elements by role, scoped to the bounding box.
-
#get_by_text(text) ⇒ Object
Find elements by visible text, scoped to the bounding box.
-
#initialize(selector, element) ⇒ ScopedSelector
constructor
A new instance of ScopedSelector.
- #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
Constructor Details
#initialize(selector, element) ⇒ ScopedSelector
Returns a new instance of ScopedSelector.
16 17 18 19 20 21 22 23 24 |
# File 'lib/tans_parser/scoped_selector.rb', line 16 def initialize(selector, element) @selector = selector @element = element @state = selector.state @row_start = element.row @row_end = element.row + element.height - 1 @col_start = element.col @col_end = element.col + element.width - 1 end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
14 15 16 |
# File 'lib/tans_parser/scoped_selector.rb', line 14 def element @element end |
Instance Method Details
#button(**filters) ⇒ Object
Convenience singular accessors
67 |
# File 'lib/tans_parser/scoped_selector.rb', line 67 def (**filters) = (**filters).first |
#buttons(**filters) ⇒ Object
Convenience plural accessors
56 |
# File 'lib/tans_parser/scoped_selector.rb', line 56 def (**filters) = get_by_role(:button, **filters) |
#checkbox(**filters) ⇒ Object
68 |
# File 'lib/tans_parser/scoped_selector.rb', line 68 def checkbox(**filters) = checkboxes(**filters).first |
#checkboxes(**filters) ⇒ Object
57 |
# File 'lib/tans_parser/scoped_selector.rb', line 57 def checkboxes(**filters) = get_by_role(:checkbox, **filters) |
#dialog(**filters) ⇒ Object
69 |
# File 'lib/tans_parser/scoped_selector.rb', line 69 def dialog(**filters) = dialogs(**filters).first |
#dialogs(**filters) ⇒ Object
58 |
# File 'lib/tans_parser/scoped_selector.rb', line 58 def dialogs(**filters) = get_by_role(:dialog, **filters) |
#find_text(pattern, match: :partial) ⇒ Object
Search for text, scoped to the bounding box.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tans_parser/scoped_selector.rb', line 39 def find_text(pattern, match: :partial) results = [] grid = @state.grid max_row = [@row_end, grid.length - 1].min max_col = [@col_end, grid[0].length - 1, 0].max (@row_start..max_row).each do |r| row = grid[r] slice = row[@col_start..max_col] row_text = slice.map { |c| c[:char] }.join find_in_row(pattern, match, r, row_text, results) end results end |
#get_by_role(role, text: nil, checked: nil, disabled: nil) ⇒ Object
Find elements by role, scoped to the bounding box.
27 28 29 30 |
# File 'lib/tans_parser/scoped_selector.rb', line 27 def get_by_role(role, text: nil, checked: nil, disabled: nil) @selector.get_by_role(role, text: text, checked: checked, disabled: disabled) .select { |e| fully_within?(e) } end |
#get_by_text(text) ⇒ Object
Find elements by visible text, scoped to the bounding box.
33 34 35 36 |
# File 'lib/tans_parser/scoped_selector.rb', line 33 def get_by_text(text) @selector.get_by_text(text) .select { |e| fully_within?(e) } end |
#input(**filters) ⇒ Object
70 |
# File 'lib/tans_parser/scoped_selector.rb', line 70 def input(**filters) = inputs(**filters).first |
#inputs(**filters) ⇒ Object
59 |
# File 'lib/tans_parser/scoped_selector.rb', line 59 def inputs(**filters) = get_by_role(:input, **filters) |
#label(**filters) ⇒ Object
71 |
# File 'lib/tans_parser/scoped_selector.rb', line 71 def label(**filters) = labels(**filters).first |
#labels(**filters) ⇒ Object
60 |
# File 'lib/tans_parser/scoped_selector.rb', line 60 def labels(**filters) = get_by_role(:label, **filters) |
#menu(**filters) ⇒ Object
72 |
# File 'lib/tans_parser/scoped_selector.rb', line 72 def (**filters) = (**filters).first |
#menus(**filters) ⇒ Object
61 |
# File 'lib/tans_parser/scoped_selector.rb', line 61 def (**filters) = get_by_role(:menu, **filters) |
#progress_bar(**filters) ⇒ Object
75 |
# File 'lib/tans_parser/scoped_selector.rb', line 75 def (**filters) = (**filters).first |
#progress_bars(**filters) ⇒ Object
64 |
# File 'lib/tans_parser/scoped_selector.rb', line 64 def (**filters) = get_by_role(:progress, **filters) |
#statusbar(**filters) ⇒ Object
74 |
# File 'lib/tans_parser/scoped_selector.rb', line 74 def (**filters) = (**filters).first |
#statusbars(**filters) ⇒ Object
63 |
# File 'lib/tans_parser/scoped_selector.rb', line 63 def (**filters) = get_by_role(:statusbar, **filters) |
#tab(**filters) ⇒ Object
73 |
# File 'lib/tans_parser/scoped_selector.rb', line 73 def tab(**filters) = tabs(**filters).first |
#tabs(**filters) ⇒ Object
62 |
# File 'lib/tans_parser/scoped_selector.rb', line 62 def tabs(**filters) = get_by_role(:tab, **filters) |