Module: RMonitor::XRandRReadHelpers
- Included in:
- Devices
- Defined in:
- lib/rmonitor/helpers/xrandr_read_helpers.rb
Instance Method Summary collapse
- #collect_devices(blocks) ⇒ Object
- #extract_configuration(block) ⇒ Object
- #extract_configurations(block) ⇒ Object
- #extract_connected(block) ⇒ Object
- #extract_enabled(block) ⇒ Object
- #extract_name(block) ⇒ Object
- #extract_pos(block) ⇒ Object
- #split_blocks(devices_data) ⇒ Object
Instance Method Details
#collect_devices(blocks) ⇒ Object
11 12 13 14 15 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 11 def collect_devices(blocks) blocks.reject do |block| block.match(/\AScreen/) end end |
#extract_configuration(block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 35 def extract_configuration(block) # Consider each line except the first block.split("\n")[1..-1].each do |configuration_line| # See if it contains any current configurations if /(?<rate>\d+\.\d+)\*/ =~ configuration_line # Extract the mode (resolution) /(?<mode>\d+x\d+)/ =~ configuration_line return { :mode => mode, :rate => rate, } end end nil end |
#extract_configurations(block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 54 def extract_configurations(block) configurations = [] # Consider each line except the first block.split("\n")[1..-1].each do |configuration_block| # Extract the mode (resolution) /(?<mode>\d+x\d+)/ =~ configuration_block # Extract each supported frame rate of that mode (resolution) configuration_block.scan(/\d+\.\d+/).each do |rate| configurations << { :mode => mode, :rate => rate, } end end configurations end |
#extract_connected(block) ⇒ Object
31 32 33 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 31 def extract_connected(block) block.match(/(?<!dis)connected/) end |
#extract_enabled(block) ⇒ Object
27 28 29 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 27 def extract_enabled(block) block.match(/\d+x\d+\+\d+\+\d+/) end |
#extract_name(block) ⇒ Object
17 18 19 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 17 def extract_name(block) block.split.first end |
#extract_pos(block) ⇒ Object
21 22 23 24 25 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 21 def extract_pos(block) if /\+(?<x_pos>\d+)\+(?<y_pos>\d+)/ =~ block "#{x_pos}x#{y_pos}" end end |
#split_blocks(devices_data) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/rmonitor/helpers/xrandr_read_helpers.rb', line 3 def split_blocks(devices_data) block = / ^[^\s] .+? \n (?=[^\s]|\Z) /mx devices_data.scan(block) end |