Class: Diffed::UnifiedDiffParser::LineParser
- Inherits:
-
Object
- Object
- Diffed::UnifiedDiffParser::LineParser
- Defined in:
- lib/parsers/unified.rb
Instance Method Summary collapse
- #increment(left_counter, right_counter) ⇒ Object
-
#initialize(line_text) ⇒ LineParser
constructor
A new instance of LineParser.
- #line(left_counter, right_counter) ⇒ Object
Constructor Details
#initialize(line_text) ⇒ LineParser
Returns a new instance of LineParser.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/parsers/unified.rb', line 60 def initialize(line_text) @line_text = line_text if line_text.start_with? "-" @type = :left elsif line_text.start_with? "+" @type = :right elsif line_text.start_with? " " @type = :both else raise "Unparseable line: #{line}" end end |
Instance Method Details
#increment(left_counter, right_counter) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/parsers/unified.rb', line 74 def increment(left_counter, right_counter) case @type when :left [left_counter + 1, right_counter] when :right [left_counter, right_counter + 1] when :both [left_counter + 1, right_counter + 1] end end |
#line(left_counter, right_counter) ⇒ Object
85 86 87 |
# File 'lib/parsers/unified.rb', line 85 def line(left_counter, right_counter) Line.new(@type, @line_text, left_line_num(left_counter), right_line_num(right_counter)) end |