Module: Differ
- Defined in:
- lib/differ.rb,
lib/differ/diff.rb,
lib/differ/change.rb,
lib/differ/string.rb,
lib/differ/version.rb,
lib/differ/format/html.rb,
lib/differ/format/ascii.rb,
lib/differ/format/color.rb,
lib/differ/format/patch.rb
Defined Under Namespace
Modules: Format, StringDiffer
Classes: Change, Diff
Constant Summary
collapse
- VERSION =
"1.0.0"
Class Method Summary
collapse
Class Method Details
.diff(target, source, new_sep = "\n") ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/differ.rb', line 19
def diff(target, source, new_sep = "\n")
old_sep = self.separator
self.separator = new_sep
target = target.split(new_sep)
source = source.split(new_sep)
self.separator = '' if new_sep.is_a? Regexp
@diff = Diff.new
advance(target, source) until source.empty? || target.empty?
@diff.insert(*target) || @diff.delete(*source)
return @diff
ensure
self.separator = old_sep
end
|
.diff_by_char(to, from) ⇒ Object
36
37
38
|
# File 'lib/differ.rb', line 36
def diff_by_char(to, from)
diff(to, from, '')
end
|
.diff_by_line(to, from) ⇒ Object
44
45
46
|
# File 'lib/differ.rb', line 44
def diff_by_line(to, from)
diff(to, from, "\n")
end
|
.diff_by_word(to, from) ⇒ Object
40
41
42
|
# File 'lib/differ.rb', line 40
def diff_by_word(to, from)
diff(to, from, /\b/)
end
|
52
53
54
|
# File 'lib/differ.rb', line 52
def format
return @format || Format::Ascii
end
|
48
49
50
|
# File 'lib/differ.rb', line 48
def format=(f)
@format = format_for(f)
end
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/differ.rb', line 56
def format_for(f)
if f.respond_to? :call
f
else
case f
when :ascii then Format::Ascii
when :color then Format::Color
when :html then Format::HTML
when :patch then Format::Patch
when nil then nil
else raise "Unknown format type #{f.inspect}"
end
end
end
|
.separator ⇒ Object
15
16
17
|
# File 'lib/differ.rb', line 15
def separator
@@separator
end
|
.separator=(separator) ⇒ Object
11
12
13
|
# File 'lib/differ.rb', line 11
def separator=(separator)
@@separator = separator
end
|