Class: DiffAll

Inherits:
Object
  • Object
show all
Defined in:
lib/diffall.rb

Constant Summary collapse

HASH_COMMAND =
'sha256sum'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files = []) ⇒ DiffAll



17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#hashtagsObject (readonly)

Returns the value of attribute hashtags.



14
15
16
# File 'lib/diffall.rb', line 14

def hashtags
  @hashtags
end

Class Method Details

.read_io(io) ⇒ Object



29
30
31
32
33
34
35
36
# 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

Instance Method Details

#add(str) ⇒ Object

private



67
68
69
70
71
72
# 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) ⇒ Object

Add {filename => hashtag } to @hashtags. E.g., “4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865 file1”



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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