Class: RMonitor::Commands::CL::List

Inherits:
Object
  • Object
show all
Defined in:
lib/rmonitor/commands/cl/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ List

Returns a new instance of List.



7
8
9
10
11
# File 'lib/rmonitor/commands/cl/list.rb', line 7

def initialize(options = {})
  @out = options[:out] || $stdout
  @list = options[:list] || RMonitor::Commands::List.new(options)
  @matcher = options[:matcher] || RMonitor::Matcher.new(options)
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rmonitor/commands/cl/list.rb', line 13

def execute
  profiles = @list.execute

  profiles.each do |profile|
    @out.write("#{profile[:name]}\t")

    if @matcher.invokable?(profile)
      @out.write("invokable")
    else
      @out.write("uninvokable")
    end

    profile[:devices].each do |device|
      @out.write("\t#{device[:name]}")

      if device[:mode] && device[:rate]
        @out.write(" (#{device[:mode]} #{device[:rate]})")
      elsif device[:mode]
        @out.write(" (#{device[:mode]})")
      elsif device[:rate]
        @out.write(" (#{device[:rate]})")
      end
    end

    @out.write("\n")
  end
end