ld 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -28
- data/README2.md +102 -0
- data/ld.gemspec +1 -0
- data/lib/ld.rb +3 -0
- data/lib/ld/document/document.rb +1 -1
- data/lib/ld/file/dir.rb +45 -106
- data/lib/ld/file/file.rb +33 -4
- data/lib/ld/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e256c2666589abfd51ced4014d74e9dcff24bfbe
|
4
|
+
data.tar.gz: ed4dee97ccf1e8436b899fb6ba60e8750d11719e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74b28ef6771b6d292c95829f283b3c1e26f8ed6a041717381099c0dda8a0d6c75d298bb8901ea245421351a86a3db147f50948cfd7e51b0255b6ce1bab96108e
|
7
|
+
data.tar.gz: 3151f396e5811b216802015e7321a39abaf7dbe309760d7d311c28b1f88bbabd97daaeaf9098fabd9c953d531ff28df8cc8d8eea5e95e722fe06ff707343cecd
|
data/README.md
CHANGED
@@ -118,6 +118,7 @@ Ld::Print.p users, 'id ,name, created_at'
|
|
118
118
|
|
119
119
|
## API
|
120
120
|
|
121
|
+
|
121
122
|
### Ld::Project
|
122
123
|
* `initialize table_hash = {}, project_root_path = Rails.root.to_s`
|
123
124
|
* 作用:解析一个项目的代码获得结构化的数据
|
@@ -128,10 +129,6 @@ Ld::Print.p users, 'id ,name, created_at'
|
|
128
129
|
* `to_xls path = {:file_path => "#{@root.path}/project.xls"}`
|
129
130
|
* 作用:将这个项目的代码分析结果保存到excel文件(默认在项目根目录下的project.xls)
|
130
131
|
|
131
|
-
### Ld::Document
|
132
|
-
* `initialize file`
|
133
|
-
* 作用:读一个rb文件生成api数据
|
134
|
-
|
135
132
|
### Ld::Excel
|
136
133
|
* `self.open path`
|
137
134
|
* 作用:打开一个xls文件,返回Ld::Excel实例
|
@@ -216,27 +213,3 @@ Ld::Print.p users, 'id ,name, created_at'
|
|
216
213
|
|
217
214
|
* `ls `
|
218
215
|
* 作用:输出目录中所有条目
|
219
|
-
|
220
|
-
### Ld::Print
|
221
|
-
* `self.p models, fields`
|
222
|
-
* 作用:格式化打印模型数组
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
## Development
|
228
|
-
|
229
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
230
|
-
|
231
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
232
|
-
|
233
|
-
## Contributing
|
234
|
-
|
235
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ld. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
236
|
-
|
237
|
-
|
238
|
-
## License
|
239
|
-
|
240
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
241
|
-
|
242
|
-
##
|
data/README2.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
## API
|
2
|
+
|
3
|
+
|
4
|
+
### Ld::Project
|
5
|
+
* `initialize table_hash = {}, project_root_path = Rails.root.to_s`
|
6
|
+
* 作用:解析一个项目的代码获得结构化的数据
|
7
|
+
|
8
|
+
* `print model_name, type = :relations`
|
9
|
+
* 作用:查看模型的相关信息(参数有:relations,fields,tables,routes,views,controllers)
|
10
|
+
|
11
|
+
* `to_xls path = {:file_path => "#{@root.path}/project.xls"}`
|
12
|
+
* 作用:将这个项目的代码分析结果保存到excel文件(默认在项目根目录下的project.xls)
|
13
|
+
|
14
|
+
### Ld::Excel
|
15
|
+
* `self.open path`
|
16
|
+
* 作用:打开一个xls文件,返回Ld::Excel实例
|
17
|
+
|
18
|
+
* `self.write path, &block`
|
19
|
+
* 作用:写excel(创建新的xls文件)
|
20
|
+
|
21
|
+
* `self.create path, &block`
|
22
|
+
* 作用:write的同名方法
|
23
|
+
|
24
|
+
* `read params, show_location = false`
|
25
|
+
* 示例:Ld::Excel.read "Sheet1?A1:B2"
|
26
|
+
* 作用:读xls文件中的内容,二维数组
|
27
|
+
|
28
|
+
* `read_with_location params`
|
29
|
+
* 作用:与read方法相同(但会多返回坐标数据)
|
30
|
+
|
31
|
+
### Ld::Sheet
|
32
|
+
* `set_headings headings`
|
33
|
+
* 作用:在当前sheet的主体内容顶上方添加一个表头(传入二维数组),但不写入(只有调用Ld::Excel的实例方法save才会写入io)
|
34
|
+
|
35
|
+
* `set_color color`
|
36
|
+
* 作用:设置当前sheet页的字体颜色
|
37
|
+
|
38
|
+
* `set_font_size size`
|
39
|
+
* 作用:设置当前sheet页的字体大小
|
40
|
+
|
41
|
+
* `set_font font`
|
42
|
+
* 作用:设置当前sheet页的字体
|
43
|
+
|
44
|
+
* `set_weight weight`
|
45
|
+
* 作用:设置当前sheet页的单元格宽度(暂时无效)
|
46
|
+
|
47
|
+
* `set_point point`
|
48
|
+
* 作用:设置当前sheet页的字体颜色
|
49
|
+
|
50
|
+
### Ld::File
|
51
|
+
* `self.open path`
|
52
|
+
* 作用:打开一个文件
|
53
|
+
|
54
|
+
* `children `
|
55
|
+
* 作用:返回这个目录下的所有一级目录与一级文件,如果不是目录,会报错
|
56
|
+
|
57
|
+
* `self.current `
|
58
|
+
* 作用:返回当前所在目录(Dir.pwd)
|
59
|
+
|
60
|
+
* `dir? `
|
61
|
+
* 作用:判断这是目录吗
|
62
|
+
|
63
|
+
* `file? `
|
64
|
+
* 作用:判断这是文件吗
|
65
|
+
|
66
|
+
* `find name`
|
67
|
+
* 作用:查找文件或目录,返回一个一级目录或文件,如果不存在则返回nil
|
68
|
+
|
69
|
+
* `search name, type = :all`
|
70
|
+
* 作用:精确查找,返回所有匹配的目录和文件
|
71
|
+
|
72
|
+
* `search_regexp regexp, type = :all`
|
73
|
+
* 作用:模糊查找,返回所有匹配的目录和文件
|
74
|
+
|
75
|
+
* `lines `
|
76
|
+
* 作用:如果是一个文本文件,返回所有行
|
77
|
+
|
78
|
+
* `rename new_name`
|
79
|
+
* 作用:修改名称(目录或文件均可)
|
80
|
+
|
81
|
+
* `delete `
|
82
|
+
* 作用:删除当前文件(有gets确认)
|
83
|
+
|
84
|
+
* `files `
|
85
|
+
* 作用:返回所有文件
|
86
|
+
|
87
|
+
* `parent `
|
88
|
+
* 作用:返回父目录
|
89
|
+
|
90
|
+
* `siblings `
|
91
|
+
* 作用:返回所有兄弟
|
92
|
+
|
93
|
+
* `dirs `
|
94
|
+
* 作用:返回所有目录
|
95
|
+
|
96
|
+
* `ls `
|
97
|
+
* 作用:输出目录中所有条目
|
98
|
+
|
99
|
+
### Ld::Print
|
100
|
+
* `self.p models, fields`
|
101
|
+
* 作用:格式化打印模型数组
|
102
|
+
|
data/ld.gemspec
CHANGED
data/lib/ld.rb
CHANGED
@@ -4,6 +4,7 @@ module Ld
|
|
4
4
|
end
|
5
5
|
|
6
6
|
require "ld/file/file"
|
7
|
+
require "ld/file/dir"
|
7
8
|
require "ld/file/files"
|
8
9
|
|
9
10
|
require "ld/project/project"
|
@@ -20,5 +21,7 @@ require "ld/print/print"
|
|
20
21
|
|
21
22
|
require "ld/document/document"
|
22
23
|
|
24
|
+
require "ld/document/parse_html"
|
25
|
+
|
23
26
|
|
24
27
|
|
data/lib/ld/document/document.rb
CHANGED
data/lib/ld/file/dir.rb
CHANGED
@@ -1,123 +1,62 @@
|
|
1
1
|
class Ld::Dir
|
2
2
|
|
3
|
-
attr_accessor :path, :name, :
|
3
|
+
attr_accessor :path, :name, :dirs, :files, :others, :all_files, :all_dirs, :all_others
|
4
|
+
attr_accessor :all_others_sum, :all_files_sum
|
4
5
|
|
5
|
-
def initialize path
|
6
|
+
def initialize path
|
6
7
|
@path = path
|
7
|
-
@
|
8
|
-
@
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
@name = @path.split('/').last
|
9
|
+
@my = Ld::File.new @path
|
10
|
+
get_all
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_all
|
14
|
+
@all = @my.search_regexp //, :all
|
15
|
+
@all_files = []
|
16
|
+
@all_dirs = []
|
17
|
+
@all_others = []
|
18
|
+
@all.each do |a|
|
19
|
+
case a.type
|
20
|
+
when 'directory'
|
21
|
+
@all_dirs << a
|
22
|
+
when 'file'
|
23
|
+
@all_files << a
|
20
24
|
else
|
21
|
-
@
|
22
|
-
end
|
25
|
+
@all_others << a
|
23
26
|
end
|
24
27
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
dir2.iter_all
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# 移动文件夹
|
35
|
-
def mv_to dir
|
36
|
-
files.each do |file|
|
37
|
-
file.mv dir
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# 创建文件夹
|
42
|
-
def mkdir name
|
43
|
-
Dir.mkdir "#{path}/#{name}"
|
44
|
-
end
|
45
|
-
|
46
|
-
# 删除文件夹以及其下所有文件与目录
|
47
|
-
def destroy_all
|
48
|
-
# FileUtils.rm_r path
|
49
|
-
end
|
50
|
-
|
51
|
-
# 创建文件
|
52
|
-
def create_file name
|
53
|
-
File.new "#{@path}/#{name}"
|
54
|
-
end
|
55
|
-
|
56
|
-
# 创建文件夹
|
57
|
-
def create_dir name
|
58
|
-
Dir.mkdir "#{@path}/#{name}"
|
59
|
-
end
|
60
|
-
|
61
|
-
def print_tree
|
62
|
-
dirs.each do |dir|
|
63
|
-
puts "#{dir.name}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# 查看当前目录文件总大小
|
68
|
-
def files_count
|
69
|
-
sum = 0
|
70
|
-
files.each do |file|
|
71
|
-
sum += file.size
|
72
|
-
end
|
73
|
-
sum
|
74
|
-
end
|
75
|
-
|
76
|
-
# 查看当前目录下所有文件个数
|
77
|
-
def sum_files_count count = 0
|
78
|
-
@@sum_count = count + files.size
|
79
|
-
# puts "#{@@sum_count}\t+=\t#{count}\t+\t#{files.size}"
|
80
|
-
dirs.each do |dir|
|
81
|
-
dir.sum_files_count @@sum_count
|
82
|
-
end
|
83
|
-
@@sum_count
|
84
|
-
end
|
85
|
-
|
86
|
-
# 查看当前目录下所有文件个数
|
87
|
-
def sum_files_size size = 0
|
88
|
-
@@sum_size = size + files_count
|
89
|
-
# puts "#{@@sum_size}\t+=\t#{size}\t+\t#{files_count/1024.round(3)} (#{name})"
|
90
|
-
dirs.each do |dir|
|
91
|
-
dir.sum_files_size @@sum_size
|
92
|
-
end
|
93
|
-
@@sum_size
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
# 迭代打印当前目录下所有文件与文件夹的信息
|
98
|
-
def info_all(i = 0)
|
99
|
-
info(i)
|
100
|
-
files_info(i)
|
101
|
-
i += 1
|
102
|
-
dirs.each_with_index do |dir,k|
|
103
|
-
dir.info_all(i)
|
28
|
+
@all_files_sum = (@all_files.map(&:size).sum.to_f / 1024 / 1024).round(1)
|
29
|
+
@all_others_sum = (@all_others.map(&:size).sum.to_i / 1024).round(1)
|
30
|
+
@all_suffix = {}
|
31
|
+
@all_files.map(&:suffix).uniq.each do |suffix|
|
32
|
+
@all_suffix[suffix] = get_suffix_count(suffix)
|
104
33
|
end
|
105
34
|
nil
|
106
35
|
end
|
107
36
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
37
|
+
def get_suffix_count suffix
|
38
|
+
count = 0
|
39
|
+
size = 0
|
40
|
+
@all_files.each do |f|
|
41
|
+
if f.suffix == suffix
|
42
|
+
count += 1
|
43
|
+
size += f.size
|
44
|
+
end
|
112
45
|
end
|
113
|
-
|
46
|
+
return [count, (size.to_f / 1024).round(2)]
|
114
47
|
end
|
115
48
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
49
|
+
def details
|
50
|
+
title = "目录名称:#{path.split('/').last}
|
51
|
+
目录:#{@all_dirs.size}(个)
|
52
|
+
文件:#{@all_files_sum}(Mb)/#{@all_files.size}(个)
|
53
|
+
其它:#{@all_others_sum}(Kb)/#{@all_others.size}(个)"
|
54
|
+
headings = ['文件类型(后缀)', '数量(个)', '大小(Kb)']
|
55
|
+
rows = @all_suffix.map{|k,v| [k, v[0], v[1]]}.sort{|b,a| a[1] <=> b[1]}
|
56
|
+
Ld::Print.print headings:headings,rows:rows,title:title
|
121
57
|
end
|
122
58
|
|
59
|
+
def search_all_suffix regexp
|
60
|
+
@all_files.select{|f| f.suffix == regexp}
|
61
|
+
end
|
123
62
|
end
|
data/lib/ld/file/file.rb
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
class Ld::File
|
2
2
|
|
3
|
-
attr_accessor :path, :name, :exist, :size, :mode, :type, :stat
|
3
|
+
attr_accessor :path, :name, :suffix, :exist, :size, :mode, :type, :stat
|
4
4
|
@@current_path = Dir.pwd
|
5
5
|
@@exclude = ['.', '..']
|
6
6
|
|
7
7
|
def initialize path
|
8
8
|
@path = path[0] == '/' ? path : "#{Dir.pwd}/#{path}"
|
9
9
|
@name = File.basename @path
|
10
|
+
read_attrs
|
11
|
+
end
|
12
|
+
|
13
|
+
#= 作用 打开一个文件
|
14
|
+
def self.open path
|
15
|
+
f = self.new path
|
16
|
+
f.read_attrs
|
17
|
+
f
|
18
|
+
end
|
19
|
+
|
20
|
+
# 编码base64
|
21
|
+
def self.base64 path
|
22
|
+
Base64.encode64(File.open(path, 'rb').read)
|
23
|
+
end
|
24
|
+
|
25
|
+
# 解码base64,并写入图片
|
26
|
+
def self.write_image_by_base64_and_path base64, path
|
27
|
+
File.open(path,'wb').write(Base64.decode64 base64)
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_attrs
|
31
|
+
@suffix = @name.split('.').last
|
32
|
+
@suffix = @suffix == @name ? nil : @suffix
|
10
33
|
if File.exist? @path
|
11
34
|
@exist = true
|
12
35
|
@type = File.ftype path
|
@@ -19,9 +42,8 @@ class Ld::File
|
|
19
42
|
end
|
20
43
|
end
|
21
44
|
|
22
|
-
|
23
|
-
|
24
|
-
self.new path
|
45
|
+
def look
|
46
|
+
puts lines
|
25
47
|
end
|
26
48
|
|
27
49
|
#= 作用 返回这个目录下的所有一级目录与一级文件,如果不是目录,会报错
|
@@ -192,4 +214,11 @@ class Ld::File
|
|
192
214
|
puts t2 - t1
|
193
215
|
end
|
194
216
|
|
217
|
+
def details
|
218
|
+
Ld::Dir.new(@path).details
|
219
|
+
end
|
220
|
+
|
195
221
|
end
|
222
|
+
|
223
|
+
|
224
|
+
|
data/lib/ld/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Dong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hpricot
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.6
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.6
|
69
83
|
description: For the sake of efficiency, The Module is my name abbreviations LD, Basically
|
70
84
|
has the following Class.
|
71
85
|
email:
|
@@ -87,6 +101,7 @@ files:
|
|
87
101
|
- Gemfile
|
88
102
|
- LICENSE.txt
|
89
103
|
- README.md
|
104
|
+
- README2.md
|
90
105
|
- Rakefile
|
91
106
|
- bin/console
|
92
107
|
- bin/setup
|
@@ -129,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
144
|
version: '0'
|
130
145
|
requirements: []
|
131
146
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.5.1
|
133
148
|
signing_key:
|
134
149
|
specification_version: 4
|
135
150
|
summary: Practical small tools.
|