Module: NodeCollapsing
- Included in:
- Node
- Defined in:
- lib/node_collapsing.rb
Overview
Module for directory collapsing functionality
Instance Method Summary collapse
-
#collapsed_path ⇒ Object
Get the collapsed path for display.
-
#collapsed_with_file? ⇒ Boolean
Check if this is a collapsed path ending with a file.
-
#collapsible? ⇒ Boolean
Check if this directory can be collapsed (only contains one child, either file or directory).
-
#deepest_collapsible_node ⇒ Object
Get the deepest node in a collapsible chain.
Instance Method Details
#collapsed_path ⇒ Object
Get the collapsed path for display
15 16 17 18 19 20 21 |
# File 'lib/node_collapsing.rb', line 15 def collapsed_path return name unless collapsible? path_parts = [name] build_collapsed_path_parts(path_parts) path_parts.join('/') end |
#collapsed_with_file? ⇒ Boolean
Check if this is a collapsed path ending with a file
33 34 35 36 37 38 |
# File 'lib/node_collapsing.rb', line 33 def collapsed_with_file? return false unless collapsible? deepest = deepest_collapsible_node deepest.children && deepest.children.nodes.length == 1 && deepest.children.nodes.first.file? end |
#collapsible? ⇒ Boolean
Check if this directory can be collapsed (only contains one child, either file or directory)
6 7 8 9 10 11 12 |
# File 'lib/node_collapsing.rb', line 6 def collapsible? return false unless dir? return false unless children && children.nodes.length == 1 return false if name == '.' # Never collapse the root node true end |
#deepest_collapsible_node ⇒ Object
Get the deepest node in a collapsible chain
24 25 26 27 28 29 30 |
# File 'lib/node_collapsing.rb', line 24 def deepest_collapsible_node current = self current = current.children.nodes.first while current.collapsible? && current.children.nodes.first.dir? current end |