ld 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ld/nodes.rb ADDED
@@ -0,0 +1,33 @@
1
+ class Ld::Nodes
2
+ attr_accessor :nodes
3
+
4
+ def initialize nodes = []
5
+ @nodes = nodes
6
+ end
7
+
8
+ def << node
9
+ @nodes << node
10
+ end
11
+
12
+ def where option
13
+ sql = ""
14
+ if option.instance_of?(String)
15
+ sql = option
16
+ elsif option.instance_of?(Hash)
17
+ sql = option.map{|k,v| "node.#{k} == #{v.instance_of?(String) ? "'#{v}'" : "#{v}"}"}.join(" and ")
18
+ end
19
+ @nodes.map{|node| if(eval(sql));node;end}.compact
20
+ end
21
+
22
+ def find id
23
+ @nodes.each{|node| return node if node.id == id}
24
+ end
25
+
26
+ def size
27
+ @nodes.size
28
+ end
29
+
30
+ def sort_by_depth
31
+ @nodes.sort{|a,b| a.depth - b.depth}
32
+ end
33
+ end
data/lib/ld/tree.rb ADDED
@@ -0,0 +1,39 @@
1
+ class Ld::Tree
2
+ attr_accessor :root_path, :root_name, :nodes, :depth, :id
3
+
4
+ def initialize root_path
5
+ @root_path = root_path
6
+ @root_name = File.basename root_path
7
+ @nodes = Ld::Nodes.new
8
+ @numbers = 0
9
+ @depth = 0
10
+ @id = 0
11
+ end
12
+
13
+ def read_tree path = @root_path
14
+ @depth+=1
15
+ Dir.foreach(path)do |p|
16
+ if !p.match(/^\./)
17
+ node = Ld::Node.new(@id+=1, @depth, "#{path}/#{p}")
18
+ @nodes << node
19
+ if node.type == 1
20
+ read_tree node.path
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def print_tree
27
+ puts "#{@root_name}:"
28
+ @nodes.sort_by_depth.each do |node|
29
+ if node.type == 1
30
+ print_tree
31
+ else
32
+ puts "\t"*node.id + "#{node.type}:#{node.name}"
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+
39
+ end
data/lib/ld/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Ld
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ld.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "ld/version"
2
+
3
+ module Ld
4
+
5
+ class Excel
6
+
7
+ end
8
+
9
+ class File
10
+
11
+ end
12
+
13
+ class Dir
14
+
15
+ end
16
+
17
+ class Node
18
+
19
+ end
20
+
21
+ class Nodes
22
+
23
+ end
24
+
25
+ class Tree
26
+
27
+ end
28
+
29
+ end
30
+
31
+ require "ld/excel"
32
+ require "ld/file"
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ld
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Liu Dong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: 这是描述.
42
+ email:
43
+ - chuangye201012@163.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".idea/.rakeTasks"
50
+ - ".idea/encodings.xml"
51
+ - ".idea/ld.iml"
52
+ - ".idea/misc.xml"
53
+ - ".idea/modules.xml"
54
+ - ".idea/scopes/scope_settings.xml"
55
+ - ".idea/vcs.xml"
56
+ - ".idea/workspace.xml"
57
+ - CODE_OF_CONDUCT.md
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - bin/console
63
+ - bin/setup
64
+ - ld.gemspec
65
+ - lib/ld.rb
66
+ - lib/ld/dir.rb
67
+ - lib/ld/excel.rb
68
+ - lib/ld/file.rb
69
+ - lib/ld/node.rb
70
+ - lib/ld/nodes.rb
71
+ - lib/ld/tree.rb
72
+ - lib/ld/version.rb
73
+ homepage: https://github.com/18810625123/ld
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.7
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: 这是总结.
98
+ test_files: []