Class: Diffed::UnifiedDiffParser::HeaderLineParser
- Inherits:
-
Object
- Object
- Diffed::UnifiedDiffParser::HeaderLineParser
- Defined in:
- lib/parsers/unified.rb
Instance Attribute Summary collapse
-
#line_nums ⇒ Object
readonly
Returns the value of attribute line_nums.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(line) ⇒ HeaderLineParser
constructor
A new instance of HeaderLineParser.
- #line ⇒ Object
- #section_complete?(left_count, right_count) ⇒ Boolean
Constructor Details
#initialize(line) ⇒ HeaderLineParser
Returns a new instance of HeaderLineParser.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/parsers/unified.rb', line 103 def initialize(line) @text = line if line =~ /^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/ @line_nums = {left: {from: $1.to_i, lines: $2.to_i}, right: {from: $3.to_i, lines: $4.to_i}} elsif line =~ /^@@ -(\d+) \+(\d+) @@/ @line_nums = {left: {from: $1.to_i, lines: $1.to_i}, right: {from: $2.to_i, lines: $2.to_i}} else raise "Unparseable header line: #{line}" end if @line_nums[:right][:lines] > @line_nums[:left][:lines] @side_to_count = :right else @side_to_count = :left end end |
Instance Attribute Details
#line_nums ⇒ Object (readonly)
Returns the value of attribute line_nums.
101 102 103 |
# File 'lib/parsers/unified.rb', line 101 def line_nums @line_nums end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
101 102 103 |
# File 'lib/parsers/unified.rb', line 101 def text @text end |
Class Method Details
.is_header?(line) ⇒ Boolean
121 122 123 |
# File 'lib/parsers/unified.rb', line 121 def self.is_header?(line) line.start_with? "@@ " end |
Instance Method Details
#line ⇒ Object
129 130 131 |
# File 'lib/parsers/unified.rb', line 129 def line @text end |
#section_complete?(left_count, right_count) ⇒ Boolean
125 126 127 |
# File 'lib/parsers/unified.rb', line 125 def section_complete?(left_count, right_count) left_count >= @line_nums[:left][:lines] && right_count >= @line_nums[:right][:lines] end |