Class: TreeRb::ContentFile

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb

Overview

contains information related to file (LeafNode)

Instance Method Summary collapse

Constructor Details

#initialize(pathname, options) ⇒ ContentFile

Returns a new instance of ContentFile.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 25

def initialize(pathname, options)
  stat = File.lstat(pathname)
  # stat.symlink?

  if options[:show_full_path]
    file_name = pathname
  else
    file_name = File.basename(pathname)
  end

  if options[:show_md5sum]
    @str = "#{MD5.file(pathname).hexdigest}  #{file_name}"
    return
  end
  if options[:show_sha1sum]
    @str = "#{SHA1.file(pathname).hexdigest}  #{file_name}"
    return
  end

  if options[:show_size]
    str = "#{file_name} #{stat.size}"
  elsif options[:show_size_human]
    str = "#{file_name} #{stat.size.to_human}"
  else
    str = "#{file_name}"
  end

  if options[:show_md5]
    str << " md5: #{MD5.file(pathname).hexdigest}"
  end

  if options[:show_sha1]
    str << " sha1: #{SHA1.file(pathname).hexdigest}"
  end

  @str = str
end

Instance Method Details

#to_strObject



63
64
65
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 63

def to_str
  @str
end