Sha256: 651551407056c662e01ce05822682f1a8ee076aaaebe5bdefc114448f2c1ee6f
Contents?: true
Size: 639 Bytes
Versions: 1
Compression:
Stored size: 639 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_tree_node(pathname) subnode = {} @node[File.basename(pathname)] = subnode @stack.push(@node) @node = subnode end def exit_tree_node(pathname) @node = @stack.pop end def visit_leaf_node(pathname) @node[File.basename(pathname)] = File.stat(pathname).size end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
treevisitor-0.1.6 | lib/treevisitor/visitors/directory_to_hash_visitor.rb |