Class: Ykytils::DirEntryItem

Inherits:
Object
  • Object
show all
Defined in:
lib/ykutils/lsutils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDirEntryItem

Returns a new instance of DirEntryItem.



8
# File 'lib/ykutils/lsutils.rb', line 8

def initialize; end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def day
  @day
end

#groupObject

Returns the value of attribute group.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def group
  @group
end

#monthObject

Returns the value of attribute month.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def month
  @month
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def name
  @name
end

#parent_dirObject

Returns the value of attribute parent_dir.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def parent_dir
  @parent_dir
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def path
  @path
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def size
  @size
end

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def time
  @time
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def type
  @type
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def user
  @user
end

#validObject

Returns the value of attribute valid.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def valid
  @valid
end

#yearObject

Returns the value of attribute year.



6
7
8
# File 'lib/ykutils/lsutils.rb', line 6

def year
  @year
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ykutils/lsutils.rb', line 51

def directory?
  @type === :DIRECTORY
end

#file?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ykutils/lsutils.rb', line 55

def file?
  @type === :FILE
end

#group_permObject



63
64
65
# File 'lib/ykutils/lsutils.rb', line 63

def group_perm
  @perm.group
end

#otherr_permObject



67
68
69
# File 'lib/ykutils/lsutils.rb', line 67

def otherr_perm
  @perm.other
end

#owner_permObject



59
60
61
# File 'lib/ykutils/lsutils.rb', line 59

def owner_perm
  @perm.owner
end

#parse(str, parent_dir, valid = true) ⇒ Object



10
11
12
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/ykutils/lsutils.rb', line 10

def parse(str, parent_dir, valid = true)
  ary = str.split(/\s+/)
  perm = ary[0]
  @type = if perm[0].chr == "d"
            :DIRECTORY
          else
            :FILE
          end
  @perm = FilePermision.new(ary[0][1..9])
  @value = ary[1]
  @user = ary[2]
  @group = ary[3]
  @size = ary[4]
  @month = ary[5]
  @day = ary[6]
  str = ary[7]
  if str =~ /:/
    @year = Time.now.year
    @time = str
  else
    @year = str
    @time = "00:00:00"
  end

  @time = ary[7]
  @name = ary[8]
  @path = File.join(parent_dir, @name)
  @parent_dir = parent_dir
  @valid = valid
end

#to_csvObject



47
48
49
# File 'lib/ykutils/lsutils.rb', line 47

def to_csv
  "#{@type},#{@perm},#{@value},#{@user},#{@group},#{@size},#{@year},#{@month},#{@day},#{@time},#{@name},#{@parent_dir},#{@valid}"
end

#to_hashObject



41
42
43
44
45
# File 'lib/ykutils/lsutils.rb', line 41

def to_hash
  { "type" => @type, "perm" => @perm.to_hash, "value" => @value, "user" => @user, "group" => @group,
    "size" => @size, "month" => @month, "day" => @day, "year" => @year,
    "time" => @time, "name" => @name, "path" => @path, "parent_dir" => @parent_dir, "valid" => @valid }
end