Class: DSAVisualizer::Visualizer
- Inherits:
-
Object
- Object
- DSAVisualizer::Visualizer
- Defined in:
- lib/dsa_visualizer/visualizer.rb
Class Method Summary collapse
- .print_comparison(ruby_code, cpp_code, explanation) ⇒ Object
- .print_header(title) ⇒ Object
- .print_memory(label, data) ⇒ Object
- .print_section(title) ⇒ Object
- .print_step(step_num, description) ⇒ Object
- .visualize_array(arr, highlight_index = nil) ⇒ Object
- .visualize_memory_layout(structure_name, elements) ⇒ Object
Class Method Details
.print_comparison(ruby_code, cpp_code, explanation) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dsa_visualizer/visualizer.rb', line 24 def self.print_comparison(ruby_code, cpp_code, explanation) puts "\n┌─ Ruby Implementation ".ljust(79, "─") + "┐" ruby_code.each_line { |line| puts "│ #{line.chomp}".ljust(79) + "│" } puts "└".ljust(79, "─") + "┘" puts "\n┌─ C++ Implementation ".ljust(79, "─") + "┐" cpp_code.each_line { |line| puts "│ #{line.chomp}".ljust(79) + "│" } puts "└".ljust(79, "─") + "┘" puts "\n💡 Core Difference:".colorize(:light_blue) puts " #{explanation}" end |
.print_header(title) ⇒ Object
3 4 5 6 7 |
# File 'lib/dsa_visualizer/visualizer.rb', line 3 def self.print_header(title) puts "\n" + "=" * 80 puts title.center(80).colorize(:cyan).bold puts "=" * 80 + "\n" end |
.print_memory(label, data) ⇒ Object
18 19 20 21 22 |
# File 'lib/dsa_visualizer/visualizer.rb', line 18 def self.print_memory(label, data) puts "\n#{label}:".colorize(:magenta) puts " Memory Address: #{data.object_id}".colorize(:light_black) puts " Value: #{data.inspect}" end |
.print_section(title) ⇒ Object
9 10 11 12 |
# File 'lib/dsa_visualizer/visualizer.rb', line 9 def self.print_section(title) puts "\n#{title}".colorize(:yellow).bold puts "-" * 60 end |
.print_step(step_num, description) ⇒ Object
14 15 16 |
# File 'lib/dsa_visualizer/visualizer.rb', line 14 def self.print_step(step_num, description) puts "\n[Step #{step_num}] ".colorize(:green) + description end |
.visualize_array(arr, highlight_index = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dsa_visualizer/visualizer.rb', line 37 def self.visualize_array(arr, highlight_index = nil) print "\n[" arr.each_with_index do |val, idx| if idx == highlight_index print " #{val} ".colorize(:background => :green) else print " #{val} " end print "|" unless idx == arr.length - 1 end puts "]" end |
.visualize_memory_layout(structure_name, elements) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/dsa_visualizer/visualizer.rb', line 50 def self.visualize_memory_layout(structure_name, elements) puts "\n📦 Memory Layout (#{structure_name}):".colorize(:cyan) elements.each_with_index do |elem, idx| addr = elem.object_id puts " [#{idx}] Address: 0x#{addr.to_s(16)} → Value: #{elem}" end end |