dirfy 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9baf3d0385df461b2d8557113658e3a9c49a6410e96bf81022fe72956c0b958f
4
- data.tar.gz: 2358d42079537d3f2c8d9de9ca0518381add42673b0838c690d4ad57d09792da
3
+ metadata.gz: '091f923fd003168f8aa3ac21565ea9cd6513e35bae27cfe3d26812b4bb0c6318'
4
+ data.tar.gz: 5ba1b8ebb2deaca12953abfdaacd53e27303280612bb6dfdd2714760b20d55e5
5
5
  SHA512:
6
- metadata.gz: d1a052b6c69e6d8bc7fc7a99564a15f6336f949c942649c5c0bb904fe7070c3b1b719b2a8e9d965c096d33d444925876bcdbe7beab3a59c945fedafb5f756649
7
- data.tar.gz: db1c3f4085caa42ac0360d23b4228d16d576f3e371e85eba27c4f3612cb407ec76dcfb97381917c5bf007e9bc0b65d2023dab072573b4d0547baec21afa880ae
6
+ metadata.gz: e59597344884b1c72902174a126530a0eb724e04b56a6370c09f47cb217808328f690f6c5139a11574da681bb66beeb6da596afa9e97d701937c0217255b2afb
7
+ data.tar.gz: e6c03d9771e04bd2fba4c5d8bc96cfc40d6defbff2488e6348818232c05c68e30553819d43e89711684f12c0013d0db6815b6f8ae266fa045428bf3225e09ea4
data/lib/dirfy/parser.rb CHANGED
@@ -13,6 +13,8 @@ module Dirfy
13
13
  def parse(lines)
14
14
  stack = []
15
15
  items = []
16
+ depths = []
17
+ names = []
16
18
 
17
19
  lines.each do |raw|
18
20
  line = raw.rstrip
@@ -31,14 +33,24 @@ module Dirfy
31
33
 
32
34
  stack[depth] = name
33
35
  stack = stack[0..depth]
34
-
35
- # build full path
36
+ # build full path (no trailing slash yet)
36
37
  path = stack.map { |c| c.chomp("/") }.join("/")
37
- path << "/" if name.end_with?("/")
38
+ depths << depth
39
+ names << name
38
40
  items << path
39
41
  end
40
42
 
41
- items
43
+ # Second pass: infer directories by depth
44
+ items.each_with_index.map do |path, i|
45
+ is_dir = directory?(names[i], i, depths)
46
+ is_dir ? (path.end_with?("/") ? path : "#{path}/") : path
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def directory?(name, index, depths)
53
+ name.end_with?("/") || (index < depths.size - 1 && depths[index + 1] > depths[index])
42
54
  end
43
55
  end
44
56
  end
data/lib/dirfy/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Dirfy
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name