LRH_filelister 1.0.3

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/LRHfilelister.rb +104 -0
  3. metadata +63 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac5522ce14586303fb03fbeb6dd76de9bc7ed55f
4
+ data.tar.gz: ffaf4ee01ac3774f577bebc58115ea4ac98d4ddf
5
+ SHA512:
6
+ metadata.gz: b74645a1d9f8086832b51046fbcb6b4973710cc92a3f7a03e3c765cbfd733c64c1ebee993b47be2f18b2ef66ec3553326759f18b5fee78eab3b8882b4d72d892
7
+ data.tar.gz: b3e14609d010386bcdc29afefd1ec2bb1aba42247d8aee2461c1266b16cb4832c95e1b650e0dcafd1d009a425fc74f4012b1ad0e1b495ae3f7f75444ce6ce1c8
@@ -0,0 +1,104 @@
1
+ require "LRH"
2
+
3
+ class RecursiveLister < Lister
4
+ def initialize(dir, ext, filter=/.*/)
5
+ super()
6
+ set_option :dir, dir
7
+ set_option :ext, ext
8
+ set_option :filter, filter
9
+ end
10
+
11
+ def list
12
+ dir = get_option :dir
13
+ ext = get_option :ext
14
+ filter = get_option :filter
15
+
16
+ queue = [dir]
17
+
18
+ while queue.size > 0
19
+ cdir = queue.shift
20
+ Dir.entries(cdir).each do |entry|
21
+ next if ["..", "."].include? entry
22
+ file = File.join(cdir, entry)
23
+
24
+ if FileTest.directory? file
25
+ queue.push file
26
+ else
27
+ next if ext != nil && !ext.include?(File.extname(file).gsub(/[^A-Za-z]/, ""))
28
+ next if !(file =~ filter)
29
+ toy = {
30
+ :filename => file,
31
+ :path => File.basename(cdir),
32
+ :basedir => cdir
33
+ }
34
+
35
+ yield toy
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.test(dir="../../../RQ2")
42
+ LRHTest.test_lister RecursiveLister.new(dir, ['xml', 'html'])
43
+ end
44
+ end
45
+
46
+ class NonRecursiveLister < Lister
47
+ def initialize(dir, ext, filter=/.*/)
48
+ super()
49
+ set_option :dir, dir
50
+ set_option :ext, ext
51
+ set_option :filter, filter
52
+ end
53
+
54
+ def list
55
+ dir = get_option :dir
56
+ ext = get_option :ext
57
+ filter = get_option :filter
58
+
59
+ cdir = dir
60
+ Dir.entries(cdir).each do |entry|
61
+ next if ["..", "."].include? entry
62
+ file = File.join(dir, entry)
63
+
64
+ if !FileTest.directory? file
65
+ next if ext != nil && !ext.include?(File.extname(file).gsub(/[^A-Za-z]/, ""))
66
+ next if !(file =~ filter)
67
+ toy = {
68
+ :filename => file,
69
+ :path => File.basename(dir),
70
+ :basedir => dir
71
+ }
72
+
73
+ yield toy
74
+ end
75
+ end
76
+ end
77
+
78
+ def self.test(dir="../../../RQ2")
79
+ LRHTest.test_lister NonRecursiveLister.new(dir, ['xml', 'html'])
80
+ end
81
+ end
82
+
83
+ class SingleLister < Lister
84
+ def initialize(file)
85
+ super()
86
+ set_option :file, file
87
+ end
88
+
89
+ def list
90
+ file = get_option :file
91
+ cdir = File.dirname file
92
+ toy = {
93
+ :filename => file,
94
+ :path => File.basename(cdir),
95
+ :basedir => cdir
96
+ }
97
+
98
+ yield toy
99
+ end
100
+
101
+ def self.test(dir="../../../RQ2")
102
+ LRHTest.test_lister SingleLister.new("/home/test/x.alfa")
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: LRH_filelister
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Simone Scalabrino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: LRH
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.4
33
+ description: Allows to list files in the LRH framework
34
+ email: s.scalabrino9@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/LRHfilelister.rb
40
+ homepage: ''
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.6.13
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: File lister in LRH framework
63
+ test_files: []