Class: Kanrisuru::Core::Path::Parser::Ls

Inherits:
Object
  • Object
show all
Defined in:
lib/kanrisuru/core/path/parsers/ls.rb

Class Method Summary collapse

Class Method Details

.parse(command, id) ⇒ 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
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kanrisuru/core/path/parsers/ls.rb', line 8

def self.parse(command, id)
  items = []
  rows = command.to_a

  rows.each.with_index do |row, index|
    next if index.zero?

    values = row.split
    date = DateTime.parse("#{values[6]} #{values[7]} #{values[8]}")

    type = values[1].include?('d') ? 'directory' : 'file'
    items <<
      if id
        Kanrisuru::Core::Path::FileInfo.new(
          values[0].to_i,
          Kanrisuru::Mode.new(values[1]),
          values[2].to_i,
          values[3].to_i,
          values[4].to_i,
          values[5].to_i,
          date,
          values[9],
          type
        )
      else
        Kanrisuru::Core::Path::FileInfo.new(
          values[0].to_i,
          Kanrisuru::Mode.new(values[1]),
          values[2].to_i,
          values[3],
          values[4],
          values[5].to_i,
          date,
          values[9],
          type
        )
      end
  end

  items
end