Class: Cabriolet::Models::File
- Inherits:
-
Object
- Object
- Cabriolet::Models::File
- Defined in:
- lib/cabriolet/models/file.rb
Overview
File represents a file within a cabinet
Instance Attribute Summary collapse
-
#attribs ⇒ Object
Returns the value of attribute attribs.
-
#date_d ⇒ Object
Returns the value of attribute date_d.
-
#date_m ⇒ Object
Returns the value of attribute date_m.
-
#date_y ⇒ Object
Returns the value of attribute date_y.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#folder_index ⇒ Object
Returns the value of attribute folder_index.
-
#length ⇒ Object
Returns the value of attribute length.
-
#next_file ⇒ Object
Returns the value of attribute next_file.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#time_h ⇒ Object
Returns the value of attribute time_h.
-
#time_m ⇒ Object
Returns the value of attribute time_m.
-
#time_s ⇒ Object
Returns the value of attribute time_s.
Instance Method Summary collapse
-
#archived? ⇒ Boolean
Check if file is archived.
-
#continued_from_prev? ⇒ Boolean
Check if this file is continued from a previous cabinet.
-
#continued_to_next? ⇒ Boolean
Check if this file is continued to a next cabinet.
-
#executable? ⇒ Boolean
Check if file is executable.
-
#hidden? ⇒ Boolean
Check if file is hidden.
-
#initialize ⇒ File
constructor
Initialize a new file.
-
#modification_time ⇒ Time?
Get the file’s modification time as a Time object.
-
#parse_datetime(date_bits, time_bits) ⇒ void
Parse date and time from CAB format.
-
#readonly? ⇒ Boolean
Check if file is read-only.
-
#system? ⇒ Boolean
Check if file is a system file.
-
#to_s ⇒ String
Get a human-readable representation of the file.
-
#utf8_filename? ⇒ Boolean
Check if filename is UTF-8 encoded.
Constructor Details
#initialize ⇒ File
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
#attribs ⇒ Object
Returns the value of attribute attribs.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def attribs @attribs end |
#date_d ⇒ Object
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_m ⇒ Object
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_y ⇒ Object
Returns the value of attribute date_y.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def date_y @date_y end |
#filename ⇒ Object
Returns the value of attribute filename.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def filename @filename end |
#folder ⇒ Object
Returns the value of attribute folder.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def folder @folder end |
#folder_index ⇒ Object
Returns the value of attribute folder_index.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def folder_index @folder_index end |
#length ⇒ Object
Returns the value of attribute length.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def length @length end |
#next_file ⇒ Object
Returns the value of attribute next_file.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def next_file @next_file end |
#offset ⇒ Object
Returns the value of attribute offset.
9 10 11 |
# File 'lib/cabriolet/models/file.rb', line 9 def offset @offset end |
#time_h ⇒ Object
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_m ⇒ Object
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_s ⇒ Object
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
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
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
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
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
70 71 72 |
# File 'lib/cabriolet/models/file.rb', line 70 def hidden? @attribs.anybits?(Constants::ATTRIB_HIDDEN) end |
#modification_time ⇒ Time?
Get the file’s modification time as a Time object
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
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
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
77 78 79 |
# File 'lib/cabriolet/models/file.rb', line 77 def system? @attribs.anybits?(Constants::ATTRIB_SYSTEM) end |
#to_s ⇒ String
Get a human-readable representation of the file
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
56 57 58 |
# File 'lib/cabriolet/models/file.rb', line 56 def utf8_filename? @attribs.anybits?(Constants::ATTRIB_UTF_NAME) end |