Class: IRT::Differ
Defined Under Namespace
Modules: Format
Instance Method Summary collapse
-
#initialize(a, b, kind = :value, options = {}) ⇒ Differ
constructor
A new instance of Differ.
- #output ⇒ Object
Constructor Details
#initialize(a, b, kind = :value, options = {}) ⇒ Differ
Returns a new instance of Differ.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/irt/differ.rb', line 5 def initialize(a, b, kind=:value, ={}) if kind == :value a = IRT.yaml_dump a b = IRT.yaml_dump b end @a = a @b = b @options = { :a_label => 'saved', :b_label => 'actual', :a_marker => '~', :b_marker => '!' }.merge IRT::Differ::Format. = @options @diff = ::Differ.diff_by_line(@b, @a) end |
Instance Method Details
#output ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/irt/differ.rb', line 20 def output out = "\n" out << IRT.dye(' = same ', :reversed, :bold) a = "#{@options[:a_marker]} #{@options[:a_label]}" out << IRT.dye(" #{a} ", " (#{a}) ", :diff_a_color, :reversed, :bold) b = "#{@options[:b_marker]} #{@options[:b_label]}" out << IRT.dye(" #{b} ", " (#{b}) ", :diff_b_color, :reversed, :bold) out << "\n" diff = @diff.format_as(IRT::Differ::Format) out << diff.sub(/^\n/,'') out << "\n" out end |