Module: FileCrawler::Finder::Command::Collect

Included in:
FileCrawler::Finder
Defined in:
lib/file_crawler/finder/command/collect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#regexsObject

Returns the value of attribute regexs.



23
24
25
# File 'lib/file_crawler/finder/command/collect.rb', line 23

def regexs
  @regexs
end

Instance Method Details

#collect(conditions = {}) ⇒ Object



29
30
31
32
33
# File 'lib/file_crawler/finder/command/collect.rb', line 29

def collect(conditions = {})
  tap {
    @rows = collect_into_filename(@rows)
  }
end

#collect_into_filename(file_paths) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/file_crawler/finder/command/collect.rb', line 35

def collect_into_filename(file_paths)
  hash = {}

  file_paths.each {|file_path|
    filename = File.basename(file_path)
    term = decide_index_for_collect(filename)
    hash[term] ||= []
    hash[term] << file_path
  }

  hash
end

#decide_index_for_collect(string) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/file_crawler/finder/command/collect.rb', line 48

def decide_index_for_collect(string)
  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