Class: RMonitor::Actions

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

Defined Under Namespace

Classes: Builder, DSL

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Actions

Returns a new instance of Actions.



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

def initialize(options = {})
  @capabilities = options[:capabilities] || Capabilities.new(options).parse
end

Instance Method Details

#create(profile) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rmonitor/actions.rb', line 9

def create(profile)
  actions = []

  @avaialble_devices = @capabilities.map { |capability| capability[:name] }.uniq
  @desired_devices = profile[:devices].map { |device| device[:name] }

  (@avaialble_devices - @desired_devices).each do |device|
    actions << {:action => :off, :name => device}
  end

  if profile[:dpi]
    actions << {:action => :option, :name => :dpi, :value => profile[:dpi]}
  end

  profile[:devices].each do |device|
    actions << device.merge(:action => :on)
  end

  actions
end