Class: WindClutter::Analyser

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/windclutter/analyser.rb

Overview

Analyser for windclutter

Class Method Summary collapse

Class Method Details

.init(content) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/windclutter/analyser.rb', line 13

def self.init(content)
  active_project = Config.read('active_project')

  class_key = Config.read_project(active_project, 'class_key')
  class_start = Config.read_project(active_project, 'class_start')
  class_end = Config.read_project(active_project, 'class_end')

  regex = /#{class_key}=#{class_start}(?:(?!windclutter:)[^#{class_end}])*#{class_end}/
  occurrence_regex = /#{class_key}=#{class_start}([^#{class_end}]*)#{class_end}/

  collections = {}
  content.scan(regex).each do |occurrence|
    cls = occurrence.to_s.match(occurrence_regex)[1].split(' ')

    cls.each { |k| collect(collections, k, 1) }
  end
  sorter(collections).to_h
end

.traverse(suffixes, limit) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/windclutter/analyser.rb', line 32

def self.traverse(suffixes, limit)
  collection = {}
  scanned = FileHandler.scanners(suffixes)
  scanned.each do |file|
    init(FileHandler.read(file)).each { |k, v| collect(collection, k, v) }
  end

  sorted = sorter(collection)
  result = limit.positive? ? sorted.first(limit).to_h : sorted.to_h

  [sorted.count, result, scanned.count]
end