file_crawler 0.5.4 → 0.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b372fdeaca742c969b8c67c2f8494d21f9f9b1d6baad030aefcec3553f7005a3
4
- data.tar.gz: b2b7d162fb98e3e25667d5a5ebab4c6f01b799ffb7594d401d150a081ec12df4
3
+ metadata.gz: 45df35c34f7ff2a5e69f405be973487b8ca554e50e47d978ccd3dc4faa151591
4
+ data.tar.gz: c4547234a5584dea2643a9e0c9fd2240fef7edb37c08a2ed87a42d84a7edce4d
5
5
  SHA512:
6
- metadata.gz: 574615846dd7cdb0a4a8f1a29908becb3950d7cbd71c5bb0dc1becd3b70c2cf39ed93fe9557c4d27acde7aa629c91fcb75562fb66ca05b656a7d0949f5a40e38
7
- data.tar.gz: a5ad94a5d743a659fa4a1f8231054c4513bf08b32f76654673b9fb848157e32cf23dbb93f630ecc104a561c70cf4998a0809ebcc4b367599a95971b49a0a398b
6
+ metadata.gz: 9649659653a60d57256d2133d0fb4334acbbb13add40380cb9790aaf4a4e24bd208894aaaca3ffdf60f67929c4c72a701508bbaf16f3472f7f8cdaf0e508b88e
7
+ data.tar.gz: 95c70d9348993daa531229ef4e9053dc4ebc2cda2413204ad8b935ceb5cb0c4899392a09a2977ef3aa67fbd0fd2ac55d04b0d1f0433085302cd3d2513c2e8a36
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # FileCrawler
2
2
 
3
+ [![Gem-version](https://img.shields.io/gem/v/file_crawler.svg)](https://rubygems.org/gems/file_crawler) [![Build Status](https://travis-ci.org/hirohisa/file_crawler.svg?branch=master)](https://travis-ci.org/hirohisa/file_crawler)
4
+
3
5
  ## Installation
4
6
 
5
7
  Add this line to your application's Gemfile:
@@ -18,6 +20,64 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
23
+ - Create Instance
24
+
25
+ ```ruby
26
+ finder = FileCrawler::Finder.new
27
+ ```
28
+
29
+ - Find directories
30
+
31
+ ```ruby
32
+ path = '.'
33
+
34
+ finder.search(path)
35
+ p finder.directories #=> ["./bin", "./lib", "./spec", ...]
36
+ p finder.dirs #=> ["./bin", "./lib", "./spec", ...] # directories's shortname
37
+
38
+ finder.search(path, maxdepth: 1)
39
+ p finder.dirs #=> ["./bin", "./lib", "./spec"]
40
+
41
+ finder.search(path, maxdepth: 1, grep: 'sample')
42
+ p finder.dirs #=> []
43
+
44
+ ```
45
+
46
+ - Create groups per label decided by directory name
47
+
48
+ ```ruby
49
+ # collect use `directories`
50
+ # directories = ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg', '/path/path1/test 123', ...
51
+ finder.collect(regexs: ['[]', '()'])
52
+ p finder.collections
53
+ #=> { 'abcd': ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg'], 'test 123': ['/path/path1/test 123'], ... }
54
+ ```
55
+
56
+ - Move directory to destination
57
+
58
+ ```ruby
59
+ # move use `directories` or `collections`
60
+ # files = #=> ["./bin", "./lib", ...]
61
+ destination = '/var'
62
+ finder.move(destination)
63
+
64
+ # ensure destination
65
+ # [ [from, to], ... ]
66
+ p finder.targets #=> [["./bin", "/var/bin"] , ["./lib", "/var/lib"], ...]
67
+
68
+ # command output
69
+ p finder.output_mv #=> [ "mv ./bin /var/bin", "mv ./lib /var/lib", ...]
70
+
71
+ # run
72
+ finder.move(destination, dry_run: false)
73
+ ```
74
+
75
+ - Chain
76
+ ```ruby
77
+ finder.search(source, grep: 'sample').collect(regexs: ['[]']).move(destination)
78
+ ```
79
+
80
+
21
81
  ## Contributing
22
82
 
23
83
  Bug reports and pull requests are welcome on GitHub at https://github.com/hirohisa/file_crawler.
@@ -39,7 +39,7 @@ module FileCrawler::Finder::Command
39
39
  }
40
40
  end
41
41
 
42
- @collections = Organizer.new.run(@files, regexs)
42
+ @collections = Organizer.new.run(@directories, regexs)
43
43
  }
44
44
  end
45
45
 
@@ -6,7 +6,7 @@ module FileCrawler::Finder::Command
6
6
 
7
7
  def move(destination, options={dry_run: true})
8
8
  tap {
9
- target = @collections.empty? ? @files : @collections
9
+ target = @collections.empty? ? @directories : @collections
10
10
  fixer = Fixer.new
11
11
  @targets = fixer.make_new_path(target, destination)
12
12
 
@@ -18,8 +18,8 @@ module FileCrawler::Finder::Command
18
18
  }
19
19
  end
20
20
 
21
- def cmds
22
- return nil if @targets.nil?
21
+ def output_mv
22
+ return [] if @targets.nil?
23
23
 
24
24
  fixer = Fixer.new
25
25
  fixer.make_mv(@targets)
@@ -44,7 +44,7 @@ module FileCrawler::Finder::Command
44
44
  cmds = []
45
45
  mkdirs = []
46
46
  make_fixed_paths(filepaths).map {|file|
47
- mkdirs << "mkdir -p #{File.dirname(file[1])}"
47
+ mkdirs << "mkdir -p #{File.dirname(file[1]).inspect}"
48
48
  cmds << "mv #{file[0].inspect} #{file[1].inspect}"
49
49
  }
50
50
 
@@ -5,7 +5,7 @@ module FileCrawler::Finder::Command
5
5
 
6
6
  def search(path, options={})
7
7
  tap {
8
- @files = search_directories(path, options)
8
+ @directories = search_directories(path, options)
9
9
  }
10
10
  end
11
11
 
@@ -16,7 +16,7 @@ module FileCrawler::Finder::Command
16
16
  cmd = "find #{path} -maxdepth #{options[:maxdepth]} -type d"
17
17
  end
18
18
  if options[:grep]
19
- cmd += "| grep #{options[:grep]}"
19
+ cmd += "| grep #{options[:grep].inspect}"
20
20
  end
21
21
 
22
22
  exec(cmd).each_line {|item|
@@ -3,7 +3,7 @@ require_relative 'finder/command'
3
3
  module FileCrawler
4
4
 
5
5
  class Finder
6
- attr_accessor :files, :collections
6
+ attr_reader :directories, :dirs, :collections
7
7
 
8
8
  include Command::Collect
9
9
  include Command::Move
@@ -11,7 +11,10 @@ module FileCrawler
11
11
 
12
12
  def initialize
13
13
  @rows = []
14
- @collections = []
14
+ end
15
+
16
+ def dirs
17
+ @directories
15
18
  end
16
19
  end
17
20
 
@@ -1,3 +1,3 @@
1
1
  module FileCrawler
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_crawler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirohisa Kawasaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler