Class: HotOrNot::ComparisonResult
- Inherits:
-
Object
- Object
- HotOrNot::ComparisonResult
- Extended by:
- Forwardable
- Defined in:
- lib/hot_or_not/comparison_result.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
Instance Method Summary collapse
- #diff(format = :text) ⇒ Object
- #different? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(compare_url, side_a_results, side_b_results) ⇒ ComparisonResult
constructor
A new instance of ComparisonResult.
- #output_to_files_in(directory) ⇒ Object
- #side_a_body ⇒ Object
- #side_a_latency ⇒ Object
- #side_b_body ⇒ Object
- #side_b_latency ⇒ Object
- #success? ⇒ Boolean
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 = '' unless success? end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
13 14 15 |
# File 'lib/hot_or_not/comparison_result.rb', line 13 def @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. side_b_result = UrlResult.retrieve_for compare_url.side_b, compare_url. 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
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
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", 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_body ⇒ Object
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_latency ⇒ Object
22 23 24 |
# File 'lib/hot_or_not/comparison_result.rb', line 22 def side_a_latency @side_a_results.latency end |
#side_b_body ⇒ Object
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_latency ⇒ Object
26 27 28 |
# File 'lib/hot_or_not/comparison_result.rb', line 26 def side_b_latency @side_b_results.latency end |
#success? ⇒ 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 |