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.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/parsers/unified.rb', line 102 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.
100 101 102 |
# File 'lib/parsers/unified.rb', line 100 def line_nums @line_nums end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
100 101 102 |
# File 'lib/parsers/unified.rb', line 100 def text @text end |
Class Method Details
.is_header?(line) ⇒ Boolean
120 121 122 |
# File 'lib/parsers/unified.rb', line 120 def self.is_header?(line) line.start_with? "@@ " end |
Instance Method Details
#line ⇒ Object
128 129 130 |
# File 'lib/parsers/unified.rb', line 128 def line @text end |
#section_complete?(left_count, right_count) ⇒ Boolean
124 125 126 |
# File 'lib/parsers/unified.rb', line 124 def section_complete?(left_count, right_count) left_count >= @line_nums[:left][:lines] && right_count >= @line_nums[:right][:lines] end |