Class: FileCrawler::Finder::Command::Collect::Organizer
- Inherits:
-
Object
- Object
- FileCrawler::Finder::Command::Collect::Organizer
- Defined in:
- lib/file_crawler/finder/command/collect.rb
Instance Method Summary collapse
Instance Method Details
#decide_index(string, regexs = []) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/file_crawler/finder/command/collect.rb', line 61 def decide_index(string, regexs=[]) if !regexs.empty? regexs.each {|regex| return $1.strip unless regex.pattern.match(string).nil? } end pattern = /[\p{Hiragana}|\p{Katakana}|\p{Han}|[a-zA-Z0-9]ー ]+/ result = string.strip.scan(pattern).first return result.strip unless result.nil? string.strip end |
#run(filepaths, regexs) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/file_crawler/finder/command/collect.rb', line 48 def run(filepaths, regexs) hash = {} filepaths.each {|filepath| filename = File.basename(filepath) term = decide_index(filename, regexs) hash[term] ||= [] hash[term] << filepath } hash end |