dircrawl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/dircrawl.rb +56 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ff48d1b1b5e142dcddb28f8587e54d8b5f49834
4
+ data.tar.gz: 105e7772480a4b9d5c66f8a31c70fec6d7d99041
5
+ SHA512:
6
+ metadata.gz: 08d390e071f5cf5f7e7309a07d9a5c8ed3f33b827d33d2d9a493cc4d41f277397d229e37ffaa7ecb7e6e7e8c1d6044be6e6b987df55f820f26a60a623dd1a048
7
+ data.tar.gz: 9a54d1dd4e33d70fcb7034f68d0a2e731af6cd0f6154a1a45fd102a2e6fb653850762874ece3f025fab4958e668e5a1325bd4b2cc1d94b96d8ce736c72fd8ca9
data/lib/dircrawl.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'json'
2
+ require 'pry'
3
+
4
+ class DirCrawl
5
+ def initialize(path, output_dir, ignore_includes, process_block, include_block, *args)
6
+ @path = path
7
+ @output_dir = output_dir
8
+ @ignore_includes = ignore_includes
9
+ include_block.call
10
+ @process_block = process_block
11
+ @output = Array.new
12
+ crawl_dir(path, *args)
13
+ end
14
+
15
+ # Figure out where to write it
16
+ def get_write_dir(dir, file)
17
+ dir_save = dir.gsub(@path, @output_dir)
18
+ return dir_save+"/"+file
19
+ end
20
+
21
+ # Create if they don't exist
22
+ def create_write_dirs(dir)
23
+ dirs = dir.split("/")
24
+ dirs.delete("")
25
+ overallpath = ""
26
+ dirs.each do |d|
27
+ Dir.mkdir(overallpath+"/"+d) if !File.directory?(overallpath+"/"+d)
28
+ overallpath += ("/"+d)
29
+ end
30
+ end
31
+
32
+ # Crawl dir and call block for each file
33
+ def crawl_dir(dir, *args)
34
+ Dir.foreach(dir) do |file|
35
+ next if file == '.' or file == '..'
36
+ # Go to next dir
37
+ if File.directory?(dir+"/"+file)
38
+ crawl_dir(dir+"/"+file, *args)
39
+
40
+ # Process file
41
+ elsif !file.include?(@ignore_includes)
42
+ processed = @process_block.call(dir+"/"+file, *args)
43
+ @output.push(processed)
44
+
45
+ # Write to file
46
+ create_write_dirs(dir.gsub(@path, @output_dir))
47
+ File.write(get_write_dir(dir, file), JSON.pretty_generate(processed))
48
+ end
49
+ end
50
+ end
51
+
52
+ # Get the output array
53
+ def get_output
54
+ return JSON.pretty_generate(@output)
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dircrawl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - M. C. McGrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Run block on all files in dir
14
+ email: shidash@shidash.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/dircrawl.rb
20
+ homepage: https://github.com/TransparencyToolkit/dircrawl
21
+ licenses:
22
+ - GPL
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Run block on all files in dir
44
+ test_files: []
45
+ has_rdoc: