Class: Inch::Evaluation::File

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/evaluation/file.rb

Overview

Evaluation::File is used in the Suggest API/CLI to determine the importance of files

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, objects) ⇒ File

Returns a new instance of File.



8
9
10
11
12
13
# File 'lib/inch/evaluation/file.rb', line 8

def initialize(filename, objects)
  self.filename = filename
  self.objects = objects.select do |o|
    o.filename == filename
  end
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/inch/evaluation/file.rb', line 6

def filename
  @filename
end

#objectsObject

Returns the value of attribute objects.



6
7
8
# File 'lib/inch/evaluation/file.rb', line 6

def objects
  @objects
end

Class Method Details

.for(filename, objects) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/inch/evaluation/file.rb', line 53

def for(filename, objects)
  @cache ||= {}
  if (file = @cache[filename])
    file
  else
    @cache[filename] = new(filename, objects)
  end
end

Instance Method Details

#fullnameObject

Note:

added to be compatible with code objects



16
17
18
# File 'lib/inch/evaluation/file.rb', line 16

def fullname
  filename
end

#gradeObject

grade, priority and score are not meant to be displayed in the CLI they are just for internal evaluation purposes



25
26
27
# File 'lib/inch/evaluation/file.rb', line 25

def grade
  median(grades.sort_by(&:to_sym))
end

#priorityObject



29
30
31
# File 'lib/inch/evaluation/file.rb', line 29

def priority
  median(priorities.sort)
end

#scoreObject



33
34
35
# File 'lib/inch/evaluation/file.rb', line 33

def score
  objects.select(&:undocumented?).size
end