Class: Knj::Sysuser

Inherits:
Object show all
Defined in:
lib/knj/sysuser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Sysuser

Returns a new instance of Sysuser.



2
3
4
# File 'lib/knj/sysuser.rb', line 2

def initialize(data)
  @data = data
end

Class Method Details

.list(paras = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/knj/sysuser.rb', line 6

def self.list(paras = {})
  cont = File.read("/etc/passwd")
  
  list = []
  cont.split("\n").each do |line|
    linearr = line.split(":")
    
    list << Knj::Sysuser.new(
      "nick" => linearr[0],
      "home" => linearr[5],
      "shell" => linearr[6]
    )
  end
  
  return list
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
26
# File 'lib/knj/sysuser.rb', line 23

def [](key)
  raise "No such key: " + key if !@data.key?(key)
  return @data[key]
end