Skip to content

Commit

Permalink
Passage format added
Browse files Browse the repository at this point in the history
  • Loading branch information
suruja committed Mar 31, 2012
1 parent e4b0142 commit c24e4c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/differ.rb
Expand Up @@ -3,6 +3,7 @@
require 'differ/format/ascii'
require 'differ/format/color'
require 'differ/format/html'
require 'differ/format/passage'

module Differ
class << self
Expand Down Expand Up @@ -40,15 +41,16 @@ def format=(f)
end

def format
return @format || Format::Ascii
return @format || Format::Passage
end

def format_for(f)
case f
when Module then f
when :ascii then Format::Ascii
when :color then Format::Color
when :html then Format::HTML
when Module then f
when :ascii then Format::Ascii
when :color then Format::Color
when :html then Format::HTML
when :passage then Format::Passage
when nil then nil
else raise "Unknown format type #{f.inspect}"
end
Expand Down Expand Up @@ -80,4 +82,4 @@ def change(method, array, index)
@diff.same(array.shift)
end
end
end
end
28 changes: 28 additions & 0 deletions lib/differ/format/passage.rb
@@ -0,0 +1,28 @@
module Differ
module Format
module Passage
class << self
def format(change)
binding.pry
(change.change? && as_change(change)) ||
(change.delete? && as_delete(change)) ||
(change.insert? && as_insert(change)) ||
''
end

private
def as_insert(change)
"{+#{change.insert.inspect}}"
end

def as_delete(change)
"{-#{change.delete.inspect}}"
end

def as_change(change)
"{#{change.delete.inspect} >> #{change.insert.inspect}}"
end
end
end
end
end

0 comments on commit c24e4c9

Please sign in to comment.