Class: Zip::ExtraField::UniversalTime

Inherits:
Generic
  • Object
show all
Defined in:
lib/zip/extra_field/universal_time.rb

Overview

Info-ZIP Additional timestamp field

Constant Summary collapse

HEADER_ID =
"UT"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#initial_parse, name, register_map, #to_c_dir_bin, #to_local_bin

Constructor Details

#initialize(binstr = nil) ⇒ UniversalTime

Returns a new instance of UniversalTime.



7
8
9
10
11
12
13
# File 'lib/zip/extra_field/universal_time.rb', line 7

def initialize(binstr = nil)
  @ctime = nil
  @mtime = nil
  @atime = nil
  @flag  = nil
  binstr and merge(binstr)
end

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



15
16
17
# File 'lib/zip/extra_field/universal_time.rb', line 15

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



15
16
17
# File 'lib/zip/extra_field/universal_time.rb', line 15

def ctime
  @ctime
end

#flagObject

Returns the value of attribute flag.



15
16
17
# File 'lib/zip/extra_field/universal_time.rb', line 15

def flag
  @flag
end

#mtimeObject

Returns the value of attribute mtime.



15
16
17
# File 'lib/zip/extra_field/universal_time.rb', line 15

def mtime
  @mtime
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
31
# File 'lib/zip/extra_field/universal_time.rb', line 27

def ==(other)
  @mtime == other.mtime &&
    @atime == other.atime &&
    @ctime == other.ctime
end

#merge(binstr) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/zip/extra_field/universal_time.rb', line 17

def merge(binstr)
  return if binstr.empty?
  size, content = initial_parse(binstr)
  size or return
  @flag, mtime, atime, ctime = content.unpack("CVVV")
  mtime and @mtime ||= ::Zip::DOSTime.at(mtime)
  atime and @atime ||= ::Zip::DOSTime.at(atime)
  ctime and @ctime ||= ::Zip::DOSTime.at(ctime)
end

#pack_for_c_dirObject



41
42
43
44
45
# File 'lib/zip/extra_field/universal_time.rb', line 41

def pack_for_c_dir
  s = [@flag].pack("C")
  @flag & 1 == 1 and s << [@mtime.to_i].pack("V")
  s
end

#pack_for_localObject



33
34
35
36
37
38
39
# File 'lib/zip/extra_field/universal_time.rb', line 33

def pack_for_local
  s = [@flag].pack("C")
  @flag & 1 != 0 and s << [@mtime.to_i].pack("V")
  @flag & 2 != 0 and s << [@atime.to_i].pack("V")
  @flag & 4 != 0 and s << [@ctime.to_i].pack("V")
  s
end