Class: SeeingIsBelieving::Line
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Line
- Includes:
- Enumerable, HasException
- Defined in:
- lib/seeing_is_believing/line.rb
Overview
thin wrapper over an array, used by the result
Instance Attribute Summary
Attributes included from HasException
Instance Method Summary collapse
- #==(ary_or_line) ⇒ Object
-
#initialize(array = [], max_number_of_captures = Float::INFINITY) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
- #record_result(value) ⇒ Object
- #to_a ⇒ Object (also: #to_ary)
Constructor Details
#initialize(array = [], max_number_of_captures = Float::INFINITY) ⇒ Line
Returns a new instance of Line.
22 23 24 25 26 27 28 |
# File 'lib/seeing_is_believing/line.rb', line 22 def initialize(array = [], max_number_of_captures=Float::INFINITY) @array = [] @max_number_of_captures = max_number_of_captures @num_results = 0 @total_size = 0 array.each { |element| record_result element } end |
Instance Method Details
#==(ary_or_line) ⇒ Object
40 41 42 43 |
# File 'lib/seeing_is_believing/line.rb', line 40 def ==(ary_or_line) return @array == ary_or_line if Array === ary_or_line ary_or_line == @array && exception == ary_or_line.exception end |
#inspect ⇒ Object
45 46 47 48 |
# File 'lib/seeing_is_believing/line.rb', line 45 def inspect inspected_exception = has_exception? ? "#{exception.class}:#{exception..inspect}" : "no exception" "#<SIB:Line#{@array.inspect} (#@num_results, #@total_size) #{inspected_exception}>" end |
#record_result(value) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/seeing_is_believing/line.rb', line 30 def record_result(value) inspected = value.inspect # only invoke inspect once, b/c the inspection may be recorded if size < @max_number_of_captures then @array << inspected elsif size == @max_number_of_captures then @array << '...' end @num_results += 1 @total_size += inspected.size self end |
#to_a ⇒ Object Also known as: to_ary
17 18 19 |
# File 'lib/seeing_is_believing/line.rb', line 17 def to_a @array.dup end |