Class: RMonitor::Capabilities

Inherits:
Object
  • Object
show all
Defined in:
lib/rmonitor/capabilities.rb,
lib/rmonitor/capabilities/dsl.rb,
lib/rmonitor/capabilities/builder.rb

Defined Under Namespace

Classes: Builder, DSL

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Capabilities

Returns a new instance of Capabilities.



5
6
7
# File 'lib/rmonitor/capabilities.rb', line 5

def initialize(options = {})
  @xrandr = options[:xrandr] || XRandR.new(options)
end

Instance Method Details

#parse(input = @xrandr.invoke) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rmonitor/capabilities.rb', line 9

def parse(input = @xrandr.invoke)
  capabilities = []
  current_name = nil

  input = input.split("\n").tap(&:shift).map(&:strip)

  input.each do |line|
    if /(?<name>[\w\d-]+) (dis)?connected/ =~ line
      current_name = name
    end

    if /(?<mode>\d+x\d+)/ =~ line
      line.scan(/\s(\d+(?:\.\d+)?)(?:( |\*)( |\+)?)?/) do |rate, native, current|
        capabilities << {:name => current_name, :mode => mode, :rate => rate}

        if native == "*"
          capabilities.last[:native] = true
        end

        if current == "+"
          capabilities.last[:current] = true
        end
      end
    end
  end

  capabilities
end