Class: Ld::Dir
- Inherits:
-
Object
- Object
- Ld::Dir
- Defined in:
- lib/ld/file/dir.rb
Instance Attribute Summary collapse
-
#all_dirs ⇒ Object
Returns the value of attribute all_dirs.
-
#all_files ⇒ Object
Returns the value of attribute all_files.
-
#all_files_sum ⇒ Object
Returns the value of attribute all_files_sum.
-
#all_others ⇒ Object
Returns the value of attribute all_others.
-
#all_others_sum ⇒ Object
Returns the value of attribute all_others_sum.
-
#dirs ⇒ Object
Returns the value of attribute dirs.
-
#files ⇒ Object
Returns the value of attribute files.
-
#name ⇒ Object
Returns the value of attribute name.
-
#others ⇒ Object
Returns the value of attribute others.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #details ⇒ Object
- #get_all ⇒ Object
- #get_suffix_count(suffix) ⇒ Object
-
#initialize(path) ⇒ Dir
constructor
A new instance of Dir.
- #search_all_suffix(regexp) ⇒ Object
Constructor Details
Instance Attribute Details
#all_dirs ⇒ Object
Returns the value of attribute all_dirs.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def all_dirs @all_dirs end |
#all_files ⇒ Object
Returns the value of attribute all_files.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def all_files @all_files end |
#all_files_sum ⇒ Object
Returns the value of attribute all_files_sum.
4 5 6 |
# File 'lib/ld/file/dir.rb', line 4 def all_files_sum @all_files_sum end |
#all_others ⇒ Object
Returns the value of attribute all_others.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def all_others @all_others end |
#all_others_sum ⇒ Object
Returns the value of attribute all_others_sum.
4 5 6 |
# File 'lib/ld/file/dir.rb', line 4 def all_others_sum @all_others_sum end |
#dirs ⇒ Object
Returns the value of attribute dirs.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def dirs @dirs end |
#files ⇒ Object
Returns the value of attribute files.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def files @files end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def name @name end |
#others ⇒ Object
Returns the value of attribute others.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def others @others end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/ld/file/dir.rb', line 3 def path @path end |
Instance Method Details
#details ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/ld/file/dir.rb', line 49 def details title = "目录名称:#{path.split('/').last} 目录:#{@all_dirs.size}(个) 文件:#{@all_files_sum}(Mb)/#{@all_files.size}(个) 其它:#{@all_others_sum}(Kb)/#{@all_others.size}(个)" headings = ['文件类型(后缀)', '数量(个)', '大小(Kb)'] rows = @all_suffix.map{|k,v| [k, v[0], v[1]]}.sort{|b,a| a[1] <=> b[1]} Ld::Print.print headings:headings,rows:rows,title:title end |
#get_all ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ld/file/dir.rb', line 13 def get_all @all = @my.search_regexp //, :all @all_files = [] @all_dirs = [] @all_others = [] @all.each do |a| case a.type when 'directory' @all_dirs << a when 'file' @all_files << a else @all_others << a end end @all_files_sum = (@all_files.map(&:size).sum.to_f / 1024 / 1024).round(1) @all_others_sum = (@all_others.map(&:size).sum.to_i / 1024).round(1) @all_suffix = {} @all_files.map(&:suffix).uniq.each do |suffix| @all_suffix[suffix] = get_suffix_count(suffix) end nil end |
#get_suffix_count(suffix) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ld/file/dir.rb', line 37 def get_suffix_count suffix count = 0 size = 0 @all_files.each do |f| if f.suffix == suffix count += 1 size += f.size end end return [count, (size.to_f / 1024).round(2)] end |
#search_all_suffix(regexp) ⇒ Object
59 60 61 |
# File 'lib/ld/file/dir.rb', line 59 def search_all_suffix regexp @all_files.select{|f| f.suffix == regexp} end |