Class: LineByLine::Checker
- Inherits:
-
Struct
- Object
- Struct
- LineByLine::Checker
- Defined in:
- lib/linebyline.rb
Overview
The class that handles the actual checks between two lines
Instance Attribute Summary collapse
-
#failure ⇒ Object
readonly
Returns the value of attribute failure.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
-
#output_line ⇒ Object
Returns the value of attribute output_line.
-
#ref_line ⇒ Object
Returns the value of attribute ref_line.
Instance Method Summary collapse
-
#eof? ⇒ Boolean
Returns true if both lines are nil.
-
#fail!(with_message) ⇒ Object
Records the failure and the details on where it occurred in the buffer into the @failure ivar.
- #register_mismatches! ⇒ Object
Instance Attribute Details
#failure ⇒ Object (readonly)
Returns the value of attribute failure.
8 9 10 |
# File 'lib/linebyline.rb', line 8 def failure @failure end |
#lineno ⇒ Object
Returns the value of attribute lineno
6 7 8 |
# File 'lib/linebyline.rb', line 6 def lineno @lineno end |
#output_line ⇒ Object
Returns the value of attribute output_line
6 7 8 |
# File 'lib/linebyline.rb', line 6 def output_line @output_line end |
#ref_line ⇒ Object
Returns the value of attribute ref_line
6 7 8 |
# File 'lib/linebyline.rb', line 6 def ref_line @ref_line end |
Instance Method Details
#eof? ⇒ Boolean
Returns true if both lines are nil
33 34 35 |
# File 'lib/linebyline.rb', line 33 def eof? ref_line.nil? && output_line.nil? end |
#fail!(with_message) ⇒ Object
Records the failure and the details on where it occurred in the buffer into the @failure ivar
39 40 41 42 43 44 45 46 |
# File 'lib/linebyline.rb', line 39 def fail! = [ + " at line #{lineno}"] << " + #{ref_line.inspect}" << " - #{output_line.inspect}" @failure = .join("\n") throw :fail end |
#register_mismatches! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/linebyline.rb', line 10 def register_mismatches! catch :fail do if ref_line.nil? && output_line fail! "Reference buffer ended, but the output still has data" end if ref_line && output_line.nil? fail! "Reference contains chars, while the output buffer ended" end if ref_line != output_line min_len = [ref_line.length, output_line.length].sort.shift min_len.times do | offset | if ref_line[offset..offset] != output_line[offset..offset] fail! "Line mismatch at column #{offset + 1}" end end fail! "Lines have different lengths (%d expected, but was %d)" % [ref_line.length, output_line.length] end end end |