class JSONConverter
Public Class Methods
dump(tree, with_path=false)
click to toggle source
# File lib/dumb_down_viewer/visitor.rb, line 112 def self.dump(tree, with_path=false) JSON.dump(new.visit(tree, with_path)) end
Public Instance Methods
visit(node, with_path=false)
click to toggle source
# File lib/dumb_down_viewer/visitor.rb, line 116 def visit(node, with_path=false) case node when DirNode { type: 'directory', name: name_value(node, with_path), contents: node.sub_nodes.map {|n| n.accept(self, with_path) } } when FileNode { type: 'file', name: name_value(node, with_path) } end end
Private Instance Methods
name_value(node, with_path)
click to toggle source
# File lib/dumb_down_viewer/visitor.rb, line 130 def name_value(node, with_path) if with_path File.join(node.directory, node.name) else node.name end end