class Fixturex::VimgrepTreeFormatter

Public Class Methods

new(tree, stdout = $stdout) click to toggle source
# File lib/fixturex/vimgrep_tree_formatter.rb, line 5
def initialize(tree, stdout = $stdout)
  @tree = tree
  @stdout = stdout
end

Public Instance Methods

print() click to toggle source

Private Instance Methods

file_address(entry) click to toggle source
# File lib/fixturex/vimgrep_tree_formatter.rb, line 33
def file_address(entry)
  "#{entry.value.path}:#{entry.value.line}:1"
end
file_address_lengths(entry) click to toggle source
# File lib/fixturex/vimgrep_tree_formatter.rb, line 25
def file_address_lengths(entry)
  [
    file_address(entry).size
  ].concat(
    entry.children.map { |e| file_address_lengths(e) }
  ).flatten
end
print_entry(entry, indent, file_address_column_size) click to toggle source
# File lib/fixturex/vimgrep_tree_formatter.rb, line 16
def print_entry(entry, indent, file_address_column_size)
  offset = file_address_column_size - file_address(entry).size

  @stdout.puts "#{file_address(entry)}#{Array.new(offset).map { ' ' }.join}    #{indent}#{entry.value.name}"
  entry.children.each do |child_entry|
    print_entry(child_entry, "#{indent}  ", file_address_column_size)
  end
end