class DiffyC32
Public Class Methods
new(s1, s2)
click to toggle source
# File lib/diffyc32.rb, line 13 def initialize(s1, s2) html = Diffy::Diff.new(s1, s2).to_s(:html) doc = Rexle.new(html) a = doc.root.xpath('ul/li/*') a2 = a.map do |e| txt = case e.name.to_sym when :del if e.text('strong').to_s =~ /^\s+$/ then colour_strong(e, :bg_gray) else colour_strong(e, :red) end ' - '.red + ' ' + e.plaintext when :ins puts e.text('strong').to_s.inspect if e.text('strong').to_s =~ /^\s+$/ then colour_strong(e, :bg_green) else colour_strong(e) {|x| x.light_green} end ' + '.green + ' ' + e.plaintext when :span ' ' + ' ' + e.plaintext else ' ' + ' ' + e.plaintext end end @s = a2.join("\n") end
Public Instance Methods
to_s()
click to toggle source
# File lib/diffyc32.rb, line 47 def to_s() @s end
Private Instance Methods
colour_strong(e, colour=:magenta) { |text.to_s| ... }
click to toggle source
# File lib/diffyc32.rb, line 53 def colour_strong(e, colour=:magenta) # check for strong element strong = e.element('strong') if strong then strong.text = if block_given? then yield(strong.text.to_s) else strong.text.to_s.send(colour.to_sym) end end end