Class: ButlerMainframe::HostBase
- Inherits:
-
Object
- Object
- ButlerMainframe::HostBase
- Defined in:
- lib/mainframe/host_base.rb
Overview
This is the host class base that contains high level logic It uses sub method that have to be defined in the specific sub class
Direct Known Subclasses
Constant Summary collapse
- MAX_TERMINAL_COLUMNS =
80- MAX_TERMINAL_ROWS =
24
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#close_session ⇒ Object
Ends the connection and closes the session.
-
#exec_command(cmd) ⇒ Object
Execute keyboard command like PF1 or PA2 or ENTER …
-
#get_cursor_axes ⇒ Object
It returns the coordinates of the cursor.
-
#initialize(options = {}) ⇒ HostBase
constructor
A new instance of HostBase.
-
#scan(options = {}) ⇒ Object
It reads one line or an area on the screen according to parameters supplied.
-
#scan_page ⇒ Object
Scans and returns the text of the entire page.
-
#wait_session(wait = nil) ⇒ Object
Sleep time between operations.
-
#write(text, options = {}) ⇒ Object
Write text on screen at the coordinates Based on the parameters provided it writes a line or an area.
Constructor Details
#initialize(options = {}) ⇒ HostBase
Returns a new instance of HostBase.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mainframe/host_base.rb', line 12 def initialize ={} = { :session => 1, :wait => 0.01, #wait screen in seconds :wait_debug => 2, #wait time for debug purpose :debug => true, :browser_path => ButlerMainframe.configuration.browser_path, :session_path => ButlerMainframe.configuration.session_path, :close_session => :evaluate #:evaluate if the session is found will not be closed #:never never close the session #:always the session is always closed }.merge() @debug = [:debug] @wait = [:wait] @wait_debug = [:wait_debug] @session = [:session] @close_session = [:close_session] @pid = nil create_object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
If is called a not existing method there is the chance that an optional module may not have been added
226 227 228 |
# File 'lib/mainframe/host_base.rb', line 226 def method_missing method_name, *args raise NoMethodError, "Method #{method_name} not found! Please check you have included any optional modules" end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/mainframe/host_base.rb', line 6 def action @action end |
#debug ⇒ Object
Returns the value of attribute debug.
7 8 9 |
# File 'lib/mainframe/host_base.rb', line 7 def debug @debug end |
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
6 7 8 |
# File 'lib/mainframe/host_base.rb', line 6 def wait @wait end |
Instance Method Details
#close_session ⇒ Object
Ends the connection and closes the session
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mainframe/host_base.rb', line 37 def close_session puts "Closing session with criterion \"#{@close_session}\"" if @debug case @close_session when :always sub_close_session puts "Session closed" if @debug wait_session 0.1 when :evaluate if @session_started_by_me sub_close_session puts "Session closed cause started by this process" if @debug wait_session 0.1 else puts "Session not closed because it was already existing" if @debug end end @action = nil end |
#exec_command(cmd) ⇒ Object
Execute keyboard command like PF1 or PA2 or ENTER …
62 63 64 65 66 67 |
# File 'lib/mainframe/host_base.rb', line 62 def exec_command cmd cmd = "<#{cmd}>" puts "Command: #{cmd}" if @debug sub_exec_command cmd wait_session end |
#get_cursor_axes ⇒ Object
It returns the coordinates of the cursor
121 122 123 |
# File 'lib/mainframe/host_base.rb', line 121 def get_cursor_axes sub_get_cursor_axes end |
#scan(options = {}) ⇒ Object
It reads one line or an area on the screen according to parameters supplied
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mainframe/host_base.rb', line 70 def scan ={} = { :y => nil, :x => nil, :len => nil, :y1 => nil, :x1 => nil, :y2 => nil, :x2 => nil, }.merge() if [:len] scan_row [:y], [:x], [:len] else scan_area [:y1], [:x1], [:y2], [:x2] end end |
#scan_page ⇒ Object
Scans and returns the text of the entire page
83 84 85 |
# File 'lib/mainframe/host_base.rb', line 83 def scan_page scan_area 1, 1, MAX_TERMINAL_ROWS, MAX_TERMINAL_COLUMNS end |
#wait_session(wait = nil) ⇒ Object
Sleep time between operations
57 58 59 |
# File 'lib/mainframe/host_base.rb', line 57 def wait_session wait=nil sleep(wait || (@debug ? @wait_debug : @wait)) end |
#write(text, options = {}) ⇒ Object
Write text on screen at the coordinates Based on the parameters provided it writes a line or an area
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mainframe/host_base.rb', line 89 def write text, ={} = { :hook => nil, :y => nil, #riga :x => nil, #colonna :check => true, :raise_error_on_check => true, :sensible_data => nil, :clean_first_chars => nil }.merge() y=[:y] x=[:x] raise "Missing coordinates! y(row)=#{y} x(column)=#{x} " unless x && y raise "Sorry, cannot write null values" unless text bol_written = nil if [:hook] (y-2..y+2).each do |y_riga| if /#{options[:hook]}/ === scan_row(y_riga, 1, MAX_TERMINAL_COLUMNS) puts "Change y from #{y} to #{y_riga} cause hook to:#{options[:hook]}" if y_riga != y && @debug bol_written = write_clean_text_on_map text, y_riga, x, break end end end #If no control is required or was not found the label reference bol_written = write_clean_text_on_map(text, y, x, ) unless bol_written bol_written end |