Class: Canon::DiffFormatter::ByLine::BaseFormatter
- Inherits:
-
Object
- Object
- Canon::DiffFormatter::ByLine::BaseFormatter
- Defined in:
- lib/canon/diff_formatter/by_line/base_formatter.rb
Overview
Base formatter for line-by-line diffs Provides common LCS diff logic and hunk building
Direct Known Subclasses
HtmlFormatter, JsonFormatter, SimpleFormatter, XmlFormatter, YamlFormatter
Instance Attribute Summary collapse
-
#context_lines ⇒ Object
readonly
Returns the value of attribute context_lines.
-
#diff_grouping_lines ⇒ Object
readonly
Returns the value of attribute diff_grouping_lines.
-
#show_diffs ⇒ Object
readonly
Returns the value of attribute show_diffs.
-
#use_color ⇒ Object
readonly
Returns the value of attribute use_color.
-
#visualization_map ⇒ Object
readonly
Returns the value of attribute visualization_map.
Class Method Summary collapse
-
.for_format(format, **options) ⇒ BaseFormatter
Create a format-specific by-line formatter.
Instance Method Summary collapse
-
#format(doc1, doc2) ⇒ String
Format line-by-line diff Subclasses must implement this method.
-
#initialize(use_color: true, context_lines: 3, diff_grouping_lines: nil, visualization_map: nil, show_diffs: :all, differences: []) ⇒ BaseFormatter
constructor
A new instance of BaseFormatter.
Constructor Details
#initialize(use_color: true, context_lines: 3, diff_grouping_lines: nil, visualization_map: nil, show_diffs: :all, differences: []) ⇒ BaseFormatter
Returns a new instance of BaseFormatter.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 47 def initialize(use_color: true, context_lines: 3, diff_grouping_lines: nil, visualization_map: nil, show_diffs: :all, differences: []) @use_color = use_color @context_lines = context_lines @diff_grouping_lines = diff_grouping_lines @visualization_map = visualization_map @show_diffs = show_diffs @differences = differences end |
Instance Attribute Details
#context_lines ⇒ Object (readonly)
Returns the value of attribute context_lines.
13 14 15 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 13 def context_lines @context_lines end |
#diff_grouping_lines ⇒ Object (readonly)
Returns the value of attribute diff_grouping_lines.
13 14 15 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 13 def diff_grouping_lines @diff_grouping_lines end |
#show_diffs ⇒ Object (readonly)
Returns the value of attribute show_diffs.
13 14 15 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 13 def show_diffs @show_diffs end |
#use_color ⇒ Object (readonly)
Returns the value of attribute use_color.
13 14 15 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 13 def use_color @use_color end |
#visualization_map ⇒ Object (readonly)
Returns the value of attribute visualization_map.
13 14 15 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 13 def visualization_map @visualization_map end |
Class Method Details
.for_format(format, **options) ⇒ BaseFormatter
Create a format-specific by-line formatter
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 21 def self.for_format(format, **) case format when :xml require_relative "xml_formatter" XmlFormatter.new(**) when :html, :html4, :html5 require_relative "html_formatter" # Determine HTML version from format version = case format when :html5 then :html5 when :html4 then :html4 else :html4 # default to html4 end HtmlFormatter.new(html_version: version, **) when :json require_relative "json_formatter" JsonFormatter.new(**) when :yaml require_relative "yaml_formatter" YamlFormatter.new(**) else require_relative "simple_formatter" SimpleFormatter.new(**) end end |
Instance Method Details
#format(doc1, doc2) ⇒ String
Format line-by-line diff Subclasses must implement this method
64 65 66 67 |
# File 'lib/canon/diff_formatter/by_line/base_formatter.rb', line 64 def format(doc1, doc2) raise NotImplementedError, "Subclasses must implement the format method" end |