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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56b1c0421bfe77a692ac4fe8cce0fc983efbdffb
4
- data.tar.gz: 98bd4a1017ee31dc96e7292a562db54e350dcd89
3
+ metadata.gz: 4e77bb0b7e6727a74e536b0c5f6acaf24b69d9ec
4
+ data.tar.gz: ca8781f50a9fc79273f8de5170bb4e40d36f7c3c
5
5
  SHA512:
6
- metadata.gz: 756de8dbc1e566231d4865785ac34e2b151157e4c19df0c1e40f5f4769baaa695acc58a774aa010683e55a1427c5784f201ca46d40096b8092414c1d7e4b2f44
7
- data.tar.gz: 2046ac2818fac0e19b00b3d853b6dae4f42b2e85cffdeb41bc124a4d848a6d08eea8db7603b9f059d754bcd7c3591fa8de84951b7482e19f26135bbd19cb1dc4
6
+ metadata.gz: 754443d6750b069567be5988e6c54603ab0d34bedb1b38c2336412de1c192bda2f3010a689090321358020119f60f9bbc8708a24deb774e7eac074d8e1704ca1
7
+ data.tar.gz: 25e8ee3a47612156cf55e6cd1c9213b9519483e591fbd8b312594af6ba22693ddb7ed05c55146602c645edab2141d837b782137500d96a20bd6bc7a133c36b96
@@ -77,6 +77,12 @@ module FileCrawler
77
77
  }.flatten
78
78
 
79
79
  finder = FileCrawler::Finder.new
80
+ unless conditions[:regexs].nil?
81
+ conditions[:regexs].each {|regex|
82
+ finder.regexs << regex
83
+ }
84
+ end
85
+
80
86
  finder.collect(files, conditions)
81
87
  end
82
88
 
@@ -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 split_for_collect(string)
18
- pattern = /[\p{Hiragana}|\p{Katakana}|\p{Han}|[a-zA-Z0-9]ー]+/
19
- return string.scan(pattern)
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
- split_for_collect(filename).each {|term|
28
- hash[term] ||= []
29
- hash[term] << file_path
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
@@ -1,3 +1,3 @@
1
1
  module FileCrawler
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
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-28 00:00:00.000000000 Z
11
+ date: 2016-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler