Class: RubynCode::Output::DiffRenderer
- Inherits:
-
Object
- Object
- RubynCode::Output::DiffRenderer
- Defined in:
- lib/rubyn_code/output/diff_renderer.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#pastel ⇒ Object
readonly
Returns the value of attribute pastel.
Instance Method Summary collapse
-
#initialize(enabled: $stdout.tty?, context_lines: 3) ⇒ DiffRenderer
constructor
A new instance of DiffRenderer.
-
#render(old_text, new_text, filename: 'file') ⇒ String
Renders a unified diff between old_text and new_text.
Constructor Details
#initialize(enabled: $stdout.tty?, context_lines: 3) ⇒ DiffRenderer
Returns a new instance of DiffRenderer.
22 23 24 25 |
# File 'lib/rubyn_code/output/diff_renderer.rb', line 22 def initialize(enabled: $stdout.tty?, context_lines: 3) @pastel = Pastel.new(enabled: enabled) @context_lines = context_lines end |
Instance Attribute Details
#pastel ⇒ Object (readonly)
Returns the value of attribute pastel.
18 19 20 |
# File 'lib/rubyn_code/output/diff_renderer.rb', line 18 def pastel @pastel end |
Instance Method Details
#render(old_text, new_text, filename: 'file') ⇒ String
Renders a unified diff between old_text and new_text.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyn_code/output/diff_renderer.rb', line 33 def render(old_text, new_text, filename: 'file') old_lines = old_text.lines.map(&:chomp) new_lines = new_text.lines.map(&:chomp) hunks = compute_hunks(old_lines, new_lines) return pastel.dim('No differences found.') if hunks.empty? result = assemble_output(hunks, filename) $stdout.puts(result) result end |