Class: DirCat::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/dircat/cat_on_yaml/entry.rb

Overview

Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#md5Object

TODO: must be attr_reader



19
20
21
# File 'lib/dircat/cat_on_yaml/entry.rb', line 19

def md5
  @md5
end

#mtimeObject

Returns the value of attribute mtime.



23
24
25
# File 'lib/dircat/cat_on_yaml/entry.rb', line 23

def mtime
  @mtime
end

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/dircat/cat_on_yaml/entry.rb', line 20

def name
  @name
end

#pathObject

Returns the value of attribute path.



21
22
23
# File 'lib/dircat/cat_on_yaml/entry.rb', line 21

def path
  @path
end

#sizeObject

Returns the value of attribute size.



22
23
24
# File 'lib/dircat/cat_on_yaml/entry.rb', line 22

def size
  @size
end

Class Method Details

.from_filename(filename) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dircat/cat_on_yaml/entry.rb', line 25

def self.from_filename( filename )
  entry = new
  entry.name = File.basename(filename)
  entry.path = File.dirname(filename)
  stat = File.lstat(filename)
  entry.size = stat.size
  entry.mtime = stat.mtime
  # self.md5 = Digest::MD5.hexdigest(File.read( f ))
  entry.md5 = MD5.file( filename ).hexdigest unless stat.symlink?
  entry
end

.from_ser(entry_ser) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/dircat/cat_on_yaml/entry.rb', line 37

def self.from_ser( entry_ser )
  entry = new
  entry.md5   = entry_ser.md5
  entry.name  = entry_ser.name
  entry.path  = entry_ser.path
  entry.size  = entry_ser.size
  entry.mtime = entry_ser.mtime
  entry
end

Instance Method Details

#to_sObject



57
58
59
# File 'lib/dircat/cat_on_yaml/entry.rb', line 57

def to_s
  @md5 + "  " + @name + "\t " + @path + "\n"
end

#to_serObject



47
48
49
50
51
52
53
54
55
# File 'lib/dircat/cat_on_yaml/entry.rb', line 47

def to_ser
  entry_ser = EntrySer.new
  entry_ser.md5   = @md5
  entry_ser.name  = @name
  entry_ser.path  = @path
  entry_ser.size  = @size
  entry_ser.mtime = @mtime
  entry_ser
end