Class: UnixPerm

Inherits:
Object show all
Defined in:
lib/shorthand.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(v) ⇒ UnixPerm

Returns a new instance of UnixPerm.



408
# File 'lib/shorthand.rb', line 408

def initialize(v) @v = v.numeric? ? (String===v ? (v.strip[0..0]=='0' ? eval(v) : eval('0'+v)) : v) : UnixPerm.desc_to_oct(v) end

Class Method Details

.desc_to_oct(v) ⇒ Object



414
# File 'lib/shorthand.rb', line 414

def self.desc_to_oct(v) raise "not yet implemented. haven't needed it yet." end

.oct_to_desc(v, part_prefix = '') ⇒ Object



415
416
417
418
419
420
421
422
423
# File 'lib/shorthand.rb', line 415

def self.oct_to_desc(v, part_prefix='')
  s = ('0'*(3*4) + v.to_s(2))[-12..-1].each_char.map{|c| c == '1'}
  u = []; g = []; o = []; a = []
  u<<'s' if s[0]; g<<'s' if s[1];  a<<'t' if s[2]
  u<<'r' if s[3]; u<<'w' if s[4];  u<<'x' if s[5]
  g<<'r' if s[6]; g<<'w' if s[7];  g<<'x' if s[8]
  o<<'r' if s[9]; o<<'w' if s[10]; o<<'x' if s[11]
  "#{part_prefix}a=#{a.join},#{part_prefix}u=#{u.join},#{part_prefix}g=#{g.join},#{part_prefix}o=#{o.join}"
end

Instance Method Details

#as_desc_str(prefix = '') ⇒ Object



412
# File 'lib/shorthand.rb', line 412

def as_desc_str(prefix='') UnixPerm.oct_to_desc(@v,prefix)  end

#as_oct_strObject



411
# File 'lib/shorthand.rb', line 411

def as_oct_str()  '0' + @v.to_s(8) end

#inspectObject



410
# File 'lib/shorthand.rb', line 410

def inspect() as_desc_str end

#to_sObject



409
# File 'lib/shorthand.rb', line 409

def to_s()    as_oct_str  end