Class: Kronk::Diff::Output::Section
- Inherits:
-
Object
- Object
- Kronk::Diff::Output::Section
- Defined in:
- lib/kronk/diff/output.rb
Overview
Represents one diff section to render (starts with @@-line,len +line,len@@)
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#format ⇒ Object
Returns the value of attribute format.
-
#lindex ⇒ Object
Returns the value of attribute lindex.
-
#llen ⇒ Object
Returns the value of attribute llen.
-
#lmeta ⇒ Object
Returns the value of attribute lmeta.
-
#rindex ⇒ Object
Returns the value of attribute rindex.
-
#rlen ⇒ Object
Returns the value of attribute rlen.
-
#rmeta ⇒ Object
Returns the value of attribute rmeta.
Instance Method Summary collapse
-
#add(obj, meta = nil) ⇒ Object
Append a line or diff section to the section.
-
#ary_to_path(ary) ⇒ Object
Create a Path String from an Array.
-
#initialize(format, line_num_width = nil, lindex = 0, rindex = 0) ⇒ Section
constructor
Create a new Section to render, with a formatter, lines column width, and start indexes for left and right side.
-
#render ⇒ Object
Build the section String output once all lines and meta has been added.
Constructor Details
#initialize(format, line_num_width = nil, lindex = 0, rindex = 0) ⇒ Section
Create a new Section to render, with a formatter, lines column width, and start indexes for left and right side.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kronk/diff/output.rb', line 20 def initialize format, line_num_width=nil, lindex=0, rindex=0 @format = format @cwidth = line_num_width @lindex = lindex @rindex = rindex @llen = 0 @rlen = 0 @lmeta = nil @rmeta = nil @lines = [] @context = 0 end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def context @context end |
#format ⇒ Object
Returns the value of attribute format.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def format @format end |
#lindex ⇒ Object
Returns the value of attribute lindex.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def lindex @lindex end |
#llen ⇒ Object
Returns the value of attribute llen.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def llen @llen end |
#lmeta ⇒ Object
Returns the value of attribute lmeta.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def @lmeta end |
#rindex ⇒ Object
Returns the value of attribute rindex.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def rindex @rindex end |
#rlen ⇒ Object
Returns the value of attribute rlen.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def rlen @rlen end |
#rmeta ⇒ Object
Returns the value of attribute rmeta.
13 14 15 |
# File 'lib/kronk/diff/output.rb', line 13 def @rmeta end |
Instance Method Details
#add(obj, meta = nil) ⇒ Object
Append a line or diff section to the section. If obj is a String, common section is assumed, if obj is an Array, a diff section is assumed.
Metadata is optional but must be an Array of 2 items if given.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kronk/diff/output.rb', line 41 def add obj, =nil @lmeta, @rmeta = if && !@lmeta && !@rmeta @lmeta = ary_to_path @lmeta if Array === @rmeta @rmeta = ary_to_path @rmeta if Array === @rmeta if String === obj add_common obj elsif Array === obj left, right = obj left.each{|o| add_left o } right.each{|o| add_right o } end end |
#ary_to_path(ary) ⇒ Object
Create a Path String from an Array. Used when the meta data given for either side of the diff is an Array.
61 62 63 |
# File 'lib/kronk/diff/output.rb', line 61 def ary_to_path ary "#{Path::DCH}#{Path.join ary}" end |
#render ⇒ Object
Build the section String output once all lines and meta has been added.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kronk/diff/output.rb', line 70 def render cleft = "#{@lindex+1},#{@llen}" cright = "#{@rindex+1},#{@rlen}" if @lmeta != @rmeta && @lmeta && @rmeta cleft << " " << @lmeta cright << " " << @rmeta else info = @lmeta || @rmeta end [@format.context(cleft, cright, info), *@lines] end |