class DocDiff::DiffFile

Attributes

src[RW]

Public Class Methods

new(src) click to toggle source
# File lib/viewdiff.rb, line 32
def initialize(src)
  src.extend(CharString)
  src.encoding = CharString.guess_encoding(src)
  src.eol = CharString.guess_eol(src)
  @src = src
end

Public Instance Methods

anatomize() click to toggle source
# File lib/viewdiff.rb, line 49
def anatomize
  case guess_diff_type(@src)
  when "classic" then return anatomize_classic(@src)
  when "context" then return anatomize_context(@src)
  when "unified" then return anatomize_unified(@src)
  else
    raise "unsupported diff format: \n#{src.inspect}"
  end
end
guess_diff_type(text) click to toggle source
# File lib/viewdiff.rb, line 40
def guess_diff_type(text)
  case
  when (/^[<>] /m).match(text)  then return "classic"
  when (/^[-+!] /m).match(text) then return "context"
  when (/^[-+]/m).match(text)   then return "unified"
  else                               return "unknown"
  end
end