Sha256: 46a43322cffbfa46008ee5419bc79fe0f3de71af64a71f7a3bc38066188476ce
Contents?: true
Size: 626 Bytes
Versions: 5
Compression:
Stored size: 626 Bytes
Contents
# -*- coding: utf-8 -*- module TreeVisitor # # Build hash with directory structure # class DirectoryToHashVisitor # < TreeVisitor::BasicTreeNodeVisitor attr_reader :root def initialize(pathname) @stack = [] @node = {} @root = @node end def enter_node(pathname) subnode = {} @node[File.basename(pathname)] = subnode @stack.push(@node) @node = subnode end def exit_node(pathname) @node = @stack.pop end def visit_leaf(pathname) @node[File.basename(pathname)] = File.stat(pathname).size end end end
Version data entries
5 entries across 5 versions & 2 rubygems