Class: HotOrNot::ComparisonResult

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hot_or_not/comparison_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compare_url, side_a_results, side_b_results) ⇒ ComparisonResult

Returns a new instance of ComparisonResult.



16
17
18
19
20
# File 'lib/hot_or_not/comparison_result.rb', line 16

def initialize(compare_url, side_a_results, side_b_results)
  @compare_url, @side_a_results, @side_b_results = compare_url, side_a_results, side_b_results
  @message = ''
  init_message unless success?
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



13
14
15
# File 'lib/hot_or_not/comparison_result.rb', line 13

def message
  @message
end

Class Method Details

.for(compare_url) ⇒ Object



6
7
8
9
10
# File 'lib/hot_or_not/comparison_result.rb', line 6

def for(compare_url)
  side_a_result = UrlResult.retrieve_for compare_url.side_a, compare_url.options
  side_b_result = UrlResult.retrieve_for compare_url.side_b, compare_url.options
  new compare_url, side_a_result, side_b_result
end

Instance Method Details

#diff(format = :text) ⇒ Object



48
49
50
# File 'lib/hot_or_not/comparison_result.rb', line 48

def diff(format = :text)
  @diff.to_s format
end

#different?Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/hot_or_not/comparison_result.rb', line 52

def different?
  return side_a_body != side_b_body if @diff.nil?
  @diff.diff != side_a_body.gsub(/^/, ' ')
end

#error?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hot_or_not/comparison_result.rb', line 36

def error?
  @side_a_results.error? || @side_b_results.error?
end

#output_to_files_in(directory) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/hot_or_not/comparison_result.rb', line 57

def output_to_files_in(directory)
  return if success?
  if error?
    write_to directory, "error", message
  else
    write_to directory, "side_a", side_a_body
    write_to directory, "side_b", side_b_body
    write_to directory, "diff", diff
  end
end

#side_a_bodyObject



40
41
42
# File 'lib/hot_or_not/comparison_result.rb', line 40

def side_a_body
  @side_a_body ||= body_by_content_type @side_a_results
end

#side_a_latencyObject



22
23
24
# File 'lib/hot_or_not/comparison_result.rb', line 22

def side_a_latency
  @side_a_results.latency
end

#side_b_bodyObject



44
45
46
# File 'lib/hot_or_not/comparison_result.rb', line 44

def side_b_body
  @side_b_body ||= body_by_content_type @side_b_results
end

#side_b_latencyObject



26
27
28
# File 'lib/hot_or_not/comparison_result.rb', line 26

def side_b_latency
  @side_b_results.latency
end

#success?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/hot_or_not/comparison_result.rb', line 30

def success?
  !error? &&
    @side_a_results.code == @side_b_results.code &&
    !different?
end