Class: Cabriolet::Models::File

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/models/file.rb

Overview

File represents a file within a cabinet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFile

Initialize a new file



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cabriolet/models/file.rb', line 13

def initialize
  @filename = nil
  @length = 0
  @offset = 0
  @folder = nil
  @folder_index = 0
  @attribs = 0
  @time_h = 0
  @time_m = 0
  @time_s = 0
  @date_d = 1
  @date_m = 1
  @date_y = 1980
  @next_file = nil
end

Instance Attribute Details

#attribsObject

Returns the value of attribute attribs.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def attribs
  @attribs
end

#date_dObject

Returns the value of attribute date_d.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def date_d
  @date_d
end

#date_mObject

Returns the value of attribute date_m.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def date_m
  @date_m
end

#date_yObject

Returns the value of attribute date_y.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def date_y
  @date_y
end

#filenameObject

Returns the value of attribute filename.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def filename
  @filename
end

#folderObject

Returns the value of attribute folder.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def folder
  @folder
end

#folder_indexObject

Returns the value of attribute folder_index.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def folder_index
  @folder_index
end

#lengthObject

Returns the value of attribute length.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def length
  @length
end

#next_fileObject

Returns the value of attribute next_file.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def next_file
  @next_file
end

#offsetObject

Returns the value of attribute offset.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def offset
  @offset
end

#time_hObject

Returns the value of attribute time_h.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def time_h
  @time_h
end

#time_mObject

Returns the value of attribute time_m.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def time_m
  @time_m
end

#time_sObject

Returns the value of attribute time_s.



9
10
11
# File 'lib/cabriolet/models/file.rb', line 9

def time_s
  @time_s
end

Instance Method Details

#archived?Boolean

Check if file is archived

Returns:

  • (Boolean)


84
85
86
# File 'lib/cabriolet/models/file.rb', line 84

def archived?
  @attribs.anybits?(Constants::ATTRIB_ARCH)
end

#continued_from_prev?Boolean

Check if this file is continued from a previous cabinet

Returns:

  • (Boolean)


98
99
100
101
# File 'lib/cabriolet/models/file.rb', line 98

def continued_from_prev?
  @folder_index == Constants::FOLDER_CONTINUED_FROM_PREV ||
    @folder_index == Constants::FOLDER_CONTINUED_PREV_AND_NEXT
end

#continued_to_next?Boolean

Check if this file is continued to a next cabinet

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/cabriolet/models/file.rb', line 106

def continued_to_next?
  @folder_index == Constants::FOLDER_CONTINUED_TO_NEXT ||
    @folder_index == Constants::FOLDER_CONTINUED_PREV_AND_NEXT
end

#executable?Boolean

Check if file is executable

Returns:

  • (Boolean)


91
92
93
# File 'lib/cabriolet/models/file.rb', line 91

def executable?
  @attribs.anybits?(Constants::ATTRIB_EXEC)
end

#hidden?Boolean

Check if file is hidden

Returns:

  • (Boolean)


70
71
72
# File 'lib/cabriolet/models/file.rb', line 70

def hidden?
  @attribs.anybits?(Constants::ATTRIB_HIDDEN)
end

#modification_timeTime?

Get the file’s modification time as a Time object

Returns:

  • (Time, nil)

    Modification time or nil if invalid



47
48
49
50
51
# File 'lib/cabriolet/models/file.rb', line 47

def modification_time
  Time.new(@date_y, @date_m, @date_d, @time_h, @time_m, @time_s)
rescue ::ArgumentError
  nil
end

#parse_datetime(date_bits, time_bits) ⇒ void

This method returns an undefined value.

Parse date and time from CAB format

Parameters:

  • date_bits (Integer)

    16-bit date value

  • time_bits (Integer)

    16-bit time value



34
35
36
37
38
39
40
41
42
# File 'lib/cabriolet/models/file.rb', line 34

def parse_datetime(date_bits, time_bits)
  @time_h = (time_bits >> 11) & 0x1F
  @time_m = (time_bits >> 5) & 0x3F
  @time_s = (time_bits & 0x1F) << 1

  @date_d = date_bits & 0x1F
  @date_m = (date_bits >> 5) & 0x0F
  @date_y = ((date_bits >> 9) & 0x7F) + 1980
end

#readonly?Boolean

Check if file is read-only

Returns:

  • (Boolean)


63
64
65
# File 'lib/cabriolet/models/file.rb', line 63

def readonly?
  @attribs.anybits?(Constants::ATTRIB_READONLY)
end

#system?Boolean

Check if file is a system file

Returns:

  • (Boolean)


77
78
79
# File 'lib/cabriolet/models/file.rb', line 77

def system?
  @attribs.anybits?(Constants::ATTRIB_SYSTEM)
end

#to_sString

Get a human-readable representation of the file

Returns:

  • (String)


114
115
116
# File 'lib/cabriolet/models/file.rb', line 114

def to_s
  "#{@filename} (#{@length} bytes)"
end

#utf8_filename?Boolean

Check if filename is UTF-8 encoded

Returns:

  • (Boolean)


56
57
58
# File 'lib/cabriolet/models/file.rb', line 56

def utf8_filename?
  @attribs.anybits?(Constants::ATTRIB_UTF_NAME)
end