Class: Stefon::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/stefon/surveyor/editor.rb

Overview

The editor is responsible for forming a team of surveyors and asking for and combining their results. The editor decides what story to run, i.e. to print recommendations or why recommendations are impossible

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Editor

Returns a new instance of Editor.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stefon/surveyor/editor.rb', line 11

def initialize(options)
  @options = options
  # currently unused
  @errors = []
  # The editor has a team of surveyors, and tells them their importance
  @team = [
    Surveyor::AddedFiles.new(options[:added_file]),
    Surveyor::AddedLines.new(options[:added_line]),
    Surveyor::DeletedFiles.new(options[:deleted_file]),
    Surveyor::DeletedLines.new(options[:deleted_line])
  ]
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



9
10
11
# File 'lib/stefon/surveyor/editor.rb', line 9

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/stefon/surveyor/editor.rb', line 8

def options
  @options
end

#teamObject (readonly)

Returns the value of attribute team.



8
9
10
# File 'lib/stefon/surveyor/editor.rb', line 8

def team
  @team
end

Instance Method Details

#combine_full_reportsObject



34
35
36
37
38
# File 'lib/stefon/surveyor/editor.rb', line 34

def combine_full_reports
  @team.reduce(Surveyor::SurveyorStore.new([])) do |a, e|
    a.merge_scores(e.call_verbose)
  end
end

#combine_short_reportsObject



24
25
26
27
28
# File 'lib/stefon/surveyor/editor.rb', line 24

def combine_short_reports
  @team.reduce(Surveyor::SurveyorStore.new) do |a, e|
    a.merge_scores(e.call)
  end
end

#full_reportObject



40
41
42
43
# File 'lib/stefon/surveyor/editor.rb', line 40

def full_report
  # sort by the scores
  combine_full_reports.sort_by { |k, v| -combine_short_reports[k] }
end

#short_reportObject



30
31
32
# File 'lib/stefon/surveyor/editor.rb', line 30

def short_report
  combine_short_reports.sort_by { |k, v| -v }
end

#summarize_resultsObject



45
46
47
48
49
50
51
# File 'lib/stefon/surveyor/editor.rb', line 45

def summarize_results
  if @options[:full_report]
    full_report.first(@options[:limit]).map(&:last).flatten
  else
    short_report.first(@options[:limit]).map(&:first).flatten
  end
end