Module: Lsattr

Defined in:
lib/AIX/Lsattr.rb

Instance Method Summary collapse

Instance Method Details

#lsattr(string) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/AIX/Lsattr.rb', line 28

def lsattr(string)

  result = Hash.new

  string.split("\n").each do |line|
      if match = %r{(\w+)\s+(\w+)\s+(.*)\s+(True|False)}.match(line)
        tmp = Hash.new
        tmp['attribute']     = match[1].to_s
        tmp['value']         = match[2].to_s
        tmp['description']   = match[3].to_s
        tmp['user_settable'] = match[4].to_s

        result[match[1]] = tmp
      else
        pp line
        raise 'regexp can not decode string'
      end
  end

  result
end

#lsattr_O(string) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/AIX/Lsattr.rb', line 4

def lsattr_O(string)

  result = Hash.new

  lines = string.split("\n")

  headers = lines[0].split(':')
  values  = lines[1].split(':')

  headers[0].gsub!("#", '')

#    raise "Wrong number of lines" if lines.count != 2


    i=0
    while i < headers.count
      tmp = Hash.new
      tmp['value'] = values[i].to_s
      result[headers[i].to_s] = tmp
      i+=1
    end

  result
end