Class: SpecViews::BatchDiff
- Inherits:
-
Object
- Object
- SpecViews::BatchDiff
- Defined in:
- app/models/spec_views/batch_diff.rb
Defined Under Namespace
Classes: Change
Instance Attribute Summary collapse
-
#directories ⇒ Object
readonly
Returns the value of attribute directories.
Instance Method Summary collapse
- #accept_by_hash!(hash) ⇒ Object
- #biggest_change ⇒ Object
- #changes ⇒ Object
-
#initialize(directories) ⇒ BatchDiff
constructor
A new instance of BatchDiff.
Constructor Details
#initialize(directories) ⇒ BatchDiff
Returns a new instance of BatchDiff.
39 40 41 |
# File 'app/models/spec_views/batch_diff.rb', line 39 def initialize(directories) @directories = directories.select(&:challenger?).select(&:champion?).reject(&:binary?) end |
Instance Attribute Details
#directories ⇒ Object (readonly)
Returns the value of attribute directories.
5 6 7 |
# File 'app/models/spec_views/batch_diff.rb', line 5 def directories @directories end |
Instance Method Details
#accept_by_hash!(hash) ⇒ Object
68 69 70 |
# File 'app/models/spec_views/batch_diff.rb', line 68 def accept_by_hash!(hash) changes.select { |change| change.hash == hash }.map(&:accept!) end |
#biggest_change ⇒ Object
64 65 66 |
# File 'app/models/spec_views/batch_diff.rb', line 64 def biggest_change changes.max_by(&:count) end |
#changes ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/spec_views/batch_diff.rb', line 43 def changes @changes ||= begin map = {} @directories.each do |directory| diffs = Diff::LCS.diff(directory.champion_html, directory.challenger_html) diffs.each do |diff| raw_diff = diff.map do |change| element = change.element element = '\r' if element == "\r" element = '\n' if element == "\n" [change.action, element] end diff_hash = raw_diff.map(&:join).join map[diff_hash] ||= Change.new(diff_hash, 0) map[diff_hash].add(directory, diff) end end map.values.filter { |change| change.count > 1 } end end |