Module: DiffMethods

Included in:
DiMaPa
Defined in:
lib/diff_methods.rb

Constant Summary collapse

FIXNUM_MAX =
2**(0.size * 8 - 2) - 1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#diff_timeoutObject

Returns the value of attribute diff_timeout.



4
5
6
# File 'lib/diff_methods.rb', line 4

def diff_timeout
  @diff_timeout
end

Instance Method Details

#diff_compute(text1, text2, checklines, deadline) ⇒ Object

Find the differences between two texts. Assumes that the texts do not have any common prefix or suffix.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/diff_methods.rb', line 79

def diff_compute(text1, text2, checklines, deadline)
  if (diffs = diff_compute_common_cases(text1, text2))
    diffs

  elsif (diffs = diff_compute_half_match(text1, text2, checklines, deadline))
    diffs

  elsif checklines && text1.length > 100 && text2.length > 100
    diff_line_mode(text1, text2, deadline)

  else
    diff_bisect(text1, text2, deadline)
  end
end

#diff_main(text1, text2, checklines = true, deadline = nil) ⇒ Object

Find the differences between two texts. Simplifies the problem by stripping any common prefix or suffix off the texts before editing.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/diff_methods.rb', line 13

def diff_main(text1, text2, checklines = true, deadline = nil)
  # Set a deadline by which time the diff must be complete.
  deadline ||= diff_new_deadline

  # Check for null inputs.
  raise ArgumentError.new("Null inputs. (diff_main)") unless text1 || text2

  # Check for equality (speedup).
  return (text1.empty? ? [] : [[:equal, text1]]) if text1 == text2

  diff_main_compute_diff(text1, text2, checklines, deadline)
end

#initializeObject



6
7
8
9
# File 'lib/diff_methods.rb', line 6

def initialize
  # Number of seconds to map a diff before giving up (0 for infinity).
  @diff_timeout = 1
end