Class: DomGlancy::ChangeAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/dom_glancy/change_anlyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(change_factors = []) ⇒ ChangeAnalyzer

Returns a new instance of ChangeAnalyzer.



5
6
7
8
9
10
11
12
13
# File 'lib/dom_glancy/change_anlyzer.rb', line 5

def initialize(change_factors = [])
  @change_factors = Array.new(change_factors)[0..4]

  @change_factors << 0   if @change_factors.length == 0
  @change_factors << 1   if @change_factors.length == 1
  @change_factors << 1.2 if @change_factors.length == 2
  @change_factors << 2   if @change_factors.length == 3
  @change_factors << 5  if @change_factors.length == 4
end

Instance Attribute Details

#change_factorsObject

Returns the value of attribute change_factors.



3
4
5
# File 'lib/dom_glancy/change_anlyzer.rb', line 3

def change_factors
  @change_factors
end

Instance Method Details

#compare(element1, element2) ⇒ Object



15
16
17
18
19
20
# File 'lib/dom_glancy/change_anlyzer.rb', line 15

def compare(element1, element2)
  change_info = element1.change_info(element2)
  deltas = change_info.map { |changed| (element1.send(changed.to_sym) - element2.send(changed.to_sym)).abs }
  comparison_value = deltas.inject { |sum, n| n + n * deltas.count * @change_factors[deltas.count] }
  comparison_value
end