module PasswdParser
def parse_passwd(content)
-
(Array)- Collection of passwd entries
Parameters:
-
content(String) -- the raw content of /etc/passwd
def parse_passwd(content) content.to_s.split("\n").map do |line| next if line[0] == '#' parse_passwd_line(line) end.compact end
def parse_passwd_line(line)
-
(Hash)- Map of entries in this line
Parameters:
-
line(String) -- a line of /etc/passwd
def parse_passwd_line(line) x = line.split(':') { 'user' => x.at(0), 'password' => x.at(1), 'uid' => x.at(2), 'gid' => x.at(3), 'desc' => x.at(4), 'home' => x.at(5), 'shell' => x.at(6), } end