class DiffAll

Constants

HASH_COMMAND

Attributes

hashtags[R]

Public Class Methods

new(files = []) click to toggle source
# File lib/diffall.rb, line 17
def initialize(files = [])
  @hashtags = {}
  files.each do |file|
    command = "#{HASH_COMMAND} #{file.escape_zsh}"
    str = `#{command}` #.sub("  #{file}", '')
    add str
    #hash_groups[hash] ||= []
    #hash_groups[hash] << file
  end
end
read_io(io) click to toggle source
# File lib/diffall.rb, line 29
def self.read_io(io)
  result = self.new
  #io.readlines.each do |line|
  io.each_line do |line|
    result.add line
  end
  result
end

Public Instance Methods

add(str) click to toggle source

private

# File lib/diffall.rb, line 67
def add(str)
  str.chomp!
  hashtag  = str[0..63]
  filename = str[66..-1]
  @hashtags[filename] = hashtag
end
show(options, io = $stdout) click to toggle source

Add {filename => hashtag } to @hashtags. E.g.,

"4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865  file1"
# File lib/diffall.rb, line 42
def show(options, io = $stdout)
  #pp @hashtags
  hashtag_files = {}
  @hashtags.each do |file, hashtag|
    hashtag_files[hashtag] ||= []
    hashtag_files[hashtag] << file
  end

  hashtag_files.keys.sort.each do |hashtag|
    files = hashtag_files[hashtag]
    next if files.size < 2
    unless options[:filename]
      io.puts hashtag
    end
    num = files.size
    num = num - 1 if options[:last_hide]
    num.times do |i|
      indent = "  "
      indent = "" if options[:filename]
      io.puts indent + files[i]
    end
  end
end