Class: Diffux::DiffClusterFinder
- Inherits:
-
Object
- Object
- Diffux::DiffClusterFinder
- Defined in:
- lib/diffux_core/diff_cluster_finder.rb
Overview
This class finds clusters in a diff. A cluster is defined as rows that are different, and are closer than DIFF_ROW_THRESHOLD pixels to its neighboring diff row.
Constant Summary collapse
- MAXIMUM_ADJACENCY_GAP =
5
Instance Method Summary collapse
-
#clusters ⇒ Array<Hash>
Calculate clusters from diff-rows that are close to each other.
-
#initialize(number_of_rows) ⇒ DiffClusterFinder
constructor
A new instance of DiffClusterFinder.
-
#percent_of_rows_different ⇒ Float
The percent of rows that are different.
-
#row_is_different(row) ⇒ Object
Tell the DiffClusterFinder about a row that is different.
Constructor Details
#initialize(number_of_rows) ⇒ DiffClusterFinder
Returns a new instance of DiffClusterFinder.
10 11 12 13 |
# File 'lib/diffux_core/diff_cluster_finder.rb', line 10 def initialize(number_of_rows) @number_of_rows = number_of_rows @rows_with_diff = SortedSet.new end |
Instance Method Details
#clusters ⇒ Array<Hash>
Calculate clusters from diff-rows that are close to each other.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/diffux_core/diff_cluster_finder.rb', line 31 def clusters results = [] @rows_with_diff.each do |row| current = results.last if !current || current[:finish] + MAXIMUM_ADJACENCY_GAP < row results << { start: row, finish: row, } else current[:finish] = row end end results end |
#percent_of_rows_different ⇒ Float
Returns the percent of rows that are different.
23 24 25 |
# File 'lib/diffux_core/diff_cluster_finder.rb', line 23 def percent_of_rows_different @rows_with_diff.length.to_f / @number_of_rows * 100 end |
#row_is_different(row) ⇒ Object
Tell the DiffClusterFinder about a row that is different.
18 19 20 |
# File 'lib/diffux_core/diff_cluster_finder.rb', line 18 def row_is_different(row) @rows_with_diff.add row end |