Class: COS::Tree
- Inherits:
-
Struct::Base
- Object
- Struct::Base
- COS::Tree
- Defined in:
- lib/cos/tree.rb
Constant Summary collapse
- MAX_DEPTH =
5
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Tree
constructor
A new instance of Tree.
-
#print_tree ⇒ Object
命令行打印树结构.
-
#to_hash ⇒ Object
输出Hash格式, 可以直接.to_json转化为json string { :resource => ”, mtime: ”…, :children => [ => resource, :children => […], => resource, :children => […], … ] }.
-
#to_object ⇒ Object
输出Object格式, 可以直接用于链式调用 { :resource => resource, :children => [ => resource, :children => […], => resource, :children => […], … ] }.
Methods included from Struct::Base::AttrHelper
#optional_attrs, #required_attrs
Constructor Details
Instance Method Details
#print_tree ⇒ Object
命令行打印树结构
47 48 49 50 |
# File 'lib/cos/tree.rb', line 47 def print_tree create_tree(path, []) puts @tree_str end |
#to_hash ⇒ Object
输出Hash格式, 可以直接.to_json转化为json string
:resource => {name: '', mtime: ''...,
:children => [
=> resource, :children => [...],
=> resource, :children => [...],
...
]
}
42 43 44 |
# File 'lib/cos/tree.rb', line 42 def to_hash create_tree(path, [], :hash) end |
#to_object ⇒ Object
输出Object格式, 可以直接用于链式调用
:resource => resource,
:children => [
{:resource => resource, :children => [...],
=> resource, :children => [...],
...
]
}
28 29 30 |
# File 'lib/cos/tree.rb', line 28 def to_object create_tree(path, [], :object) end |