file_crawler 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file_crawler/finder.rb +6 -0
- data/lib/file_crawler/finder/command/collect.rb +35 -25
- data/lib/file_crawler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e77bb0b7e6727a74e536b0c5f6acaf24b69d9ec
|
4
|
+
data.tar.gz: ca8781f50a9fc79273f8de5170bb4e40d36f7c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 754443d6750b069567be5988e6c54603ab0d34bedb1b38c2336412de1c192bda2f3010a689090321358020119f60f9bbc8708a24deb774e7eac074d8e1704ca1
|
7
|
+
data.tar.gz: 25e8ee3a47612156cf55e6cd1c9213b9519483e591fbd8b312594af6ba22693ddb7ed05c55146602c645edab2141d837b782137500d96a20bd6bc7a133c36b96
|
data/lib/file_crawler/finder.rb
CHANGED
@@ -1,22 +1,46 @@
|
|
1
1
|
module FileCrawler
|
2
|
+
class Regex
|
3
|
+
attr_accessor :regexp_start, :regexp_end
|
4
|
+
|
5
|
+
def initialize(regexp_start, regexp_end)
|
6
|
+
@regexp_start = regexp_start
|
7
|
+
@regexp_end = regexp_end
|
8
|
+
end
|
9
|
+
|
10
|
+
def pattern
|
11
|
+
/#{Regexp.escape(regexp_start)}(.+)#{Regexp.escape(regexp_end)}/
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#<#{self.class.name}: start='#{regexp_start}', end='#{regexp_end}'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
2
19
|
class Finder
|
3
20
|
module Command
|
4
21
|
module Collect
|
5
22
|
|
23
|
+
attr_accessor :regexs
|
24
|
+
|
25
|
+
def regexs
|
26
|
+
@regexs ||= []
|
27
|
+
end
|
28
|
+
|
6
29
|
def collect(file_paths, conditions = {})
|
7
30
|
collection = collect_into_filename(file_paths)
|
8
31
|
|
9
|
-
case
|
10
|
-
when !conditions[:unique].nil?
|
11
|
-
collection = unique_in_collection(collection)
|
12
|
-
end
|
13
|
-
|
14
32
|
collection
|
15
33
|
end
|
16
34
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
35
|
+
def decide_index_for_collect(string)
|
36
|
+
if !regexs.empty?
|
37
|
+
regexs.each {|regex|
|
38
|
+
return $1 unless regex.pattern.match(string).nil?
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
pattern = /[\p{Hiragana}|\p{Katakana}|\p{Han}|[a-zA-Z0-9]ー ]+/
|
43
|
+
return string.strip.scan(pattern).first
|
20
44
|
end
|
21
45
|
|
22
46
|
def collect_into_filename(file_paths)
|
@@ -24,23 +48,9 @@ module FileCrawler
|
|
24
48
|
|
25
49
|
file_paths.each {|file_path|
|
26
50
|
filename = File.basename(file_path)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
hash
|
34
|
-
end
|
35
|
-
|
36
|
-
def unique_in_collection(collection)
|
37
|
-
hash = {}
|
38
|
-
|
39
|
-
collection.sort {|(k1, v1), (k2, v2)|
|
40
|
-
v2.size <=> v1.size && k1 <=> k2
|
41
|
-
}.each {|term, file_paths|
|
42
|
-
selection = file_paths.select {|v| !hash.values.flatten.include?(v) }
|
43
|
-
hash[term] = selection unless selection.empty?
|
51
|
+
term = decide_index_for_collect(filename)
|
52
|
+
hash[term] ||= []
|
53
|
+
hash[term] << file_path
|
44
54
|
}
|
45
55
|
|
46
56
|
hash
|
data/lib/file_crawler/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirohisa Kawasaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|