Class: Ykytils::DirEntryItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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)


49
50
51
# File 'lib/ykutils/lsutils.rb', line 49

def directory?
  @type == :DIRECTORY
end

#file?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ykutils/lsutils.rb', line 53

def file?
  @type == :FILE
end

#group_permObject



61
62
63
# File 'lib/ykutils/lsutils.rb', line 61

def group_perm
  @perm.group
end

#otherr_permObject



65
66
67
# File 'lib/ykutils/lsutils.rb', line 65

def otherr_perm
  @perm.other
end

#owner_permObject



57
58
59
# File 'lib/ykutils/lsutils.rb', line 57

def owner_perm
  @perm.owner
end

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



8
9
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
# File 'lib/ykutils/lsutils.rb', line 8

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



45
46
47
# File 'lib/ykutils/lsutils.rb', line 45

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

#to_hashObject



39
40
41
42
43
# File 'lib/ykutils/lsutils.rb', line 39

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