class LLT::Review

This is pretty much the only messy class this whole gem contains. Do something about it!

Constants

VERSION

Public Instance Methods

all_diffs() click to toggle source
# File lib/llt/review.rb, line 41
def all_diffs
  @all_diffs ||= @reviewables.map do |reviewable|
    reviewable.diff.values
  end.flatten
end
Also aliased as: diffs, comparisons
comparisons()
Alias for: all_diffs
diff(gold, reviewables, comparables = nil) click to toggle source
# File lib/llt/review.rb, line 18
def diff(gold, reviewables, comparables = nil)
  parses = parse_files(Gold: gold, Reviewable: reviewables)

  @gold, @reviewables = parses.partition do |parse_data|
    parse_data.instance_of?(self.class.const_get(:Gold))
  end

  compare(comparables)
  diff_report
  all_diffs
end
diffs()
Alias for: all_diffs
report(*uris) click to toggle source
# File lib/llt/review.rb, line 30
def report(*uris)
  @reports = parse_files(Report: uris)
  @reports.each(&:report)
  @reports
end
to_xml(type = :diff) click to toggle source
# File lib/llt/review.rb, line 36
def to_xml(type = :diff)
  root_name = "#{root_identifier}-#{type}"
  XML_DECLARATION + wrap_with_tag(root_name, header + send("#{type}_to_xml"))
end

Private Instance Methods

compare(comparables = nil) click to toggle source
# File lib/llt/review.rb, line 71
def compare(comparables = nil)
  @gold.each do |gold|
    @reviewables.each { |reviewable| reviewable.compare(gold, comparables) }
  end
end
diff_report() click to toggle source
# File lib/llt/review.rb, line 51
def diff_report
  if @reviewables.one?
    all_diffs.each(&:report)
  else
    diff_report_with_cloned_reports
  end
end
diff_report_with_cloned_reports() click to toggle source

Check the comment at Comparison#report for more info

# File lib/llt/review.rb, line 60
def diff_report_with_cloned_reports
  used_golds = []
  all_diffs.each do |d|
    d.report(to_clone_or_not_to_clone?(used_golds, d.gold.id))
  end
end
diff_to_xml() click to toggle source
# File lib/llt/review.rb, line 106
def diff_to_xml
  wrap_with_tag(:comparisons, @reviewables.map(&:to_xml).join)
end
header() click to toggle source
# File lib/llt/review.rb, line 92
def header
  wrap_with_tag('files', header_files.map(&:xml_heading).join)
end
header_files() click to toggle source
# File lib/llt/review.rb, line 96
def header_files
  [@gold, @reviewables, @reports].flatten.compact
end
parse(data) click to toggle source
# File lib/llt/review.rb, line 114
def parse(data)
  self.class.const_get(:Parser).new.parse(data)
end
parse_files(files) click to toggle source
# File lib/llt/review.rb, line 77
def parse_files(files)
  to_parse = files.flat_map { |klass, uris| uris.map { |uri| [klass, uri] } }
  parse_threaded(to_parse)
end
parse_threaded(uris_with_classes) click to toggle source
# File lib/llt/review.rb, line 82
def parse_threaded(uris_with_classes)
  threads = uris_with_classes.map do |klass, uri|
    Thread.new do
      data = get_from_uri(uri)
      self.class.const_get(klass).new(uri, parse(data))
    end
  end
  threads.map { |t| t.join; t.value }
end
report_to_xml() click to toggle source
# File lib/llt/review.rb, line 110
def report_to_xml
  wrap_with_tag(:reports, @reports.map(&:to_xml).join)
end
to_clone_or_not_to_clone?(used, id) click to toggle source
# File lib/llt/review.rb, line 67
def to_clone_or_not_to_clone?(used, id)
  used.include?(id) ? true : (used << id; false)
end
wrap_with_tag(tag, content) click to toggle source
# File lib/llt/review.rb, line 100
def wrap_with_tag(tag, content)
  "<#{tag}>" +
    content +
  "</#{tag}>"
end