Class: Omnizip::Metadata::EntryMetadata
- Inherits:
-
Object
- Object
- Omnizip::Metadata::EntryMetadata
- Defined in:
- lib/omnizip/metadata/entry_metadata.rb
Overview
Model for file entry metadata Wraps CentralDirectoryHeader with a cleaner metadata API
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
Instance Method Summary collapse
-
#attributes ⇒ Integer
Get external attributes.
-
#attributes=(value) ⇒ Object
Set external attributes.
-
#comment ⇒ String
Get entry comment.
-
#comment=(value) ⇒ Object
Set entry comment.
-
#initialize(entry) ⇒ EntryMetadata
constructor
Initialize metadata for an entry.
-
#modified? ⇒ Boolean
Check if metadata has been modified.
-
#mtime ⇒ Time
Get modification time.
-
#mtime=(value) ⇒ Object
Set modification time.
-
#reset_modified ⇒ Object
Reset modified flag.
-
#to_h ⇒ Hash
Get all metadata as a hash.
-
#unix_permissions ⇒ Integer
Get Unix permissions.
-
#unix_permissions=(perms) ⇒ Object
Set Unix permissions.
Constructor Details
#initialize(entry) ⇒ EntryMetadata
Initialize metadata for an entry
12 13 14 15 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 12 def initialize(entry) @entry = entry @modified = false end |
Instance Attribute Details
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
8 9 10 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 8 def entry @entry end |
Instance Method Details
#attributes ⇒ Integer
Get external attributes
73 74 75 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 73 def attributes entry.header.external_attributes end |
#attributes=(value) ⇒ Object
Set external attributes
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 79 def attributes=(value) case value when Integer entry.header.external_attributes = value when Symbol set_attribute_flag(value) else raise ArgumentError, "attributes must be Integer or Symbol" end @modified = true end |
#comment ⇒ String
Get entry comment
19 20 21 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 19 def comment entry.comment end |
#comment=(value) ⇒ Object
Set entry comment
25 26 27 28 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 25 def comment=(value) entry.comment = value.to_s @modified = true end |
#modified? ⇒ Boolean
Check if metadata has been modified
93 94 95 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 93 def modified? @modified end |
#mtime ⇒ Time
Get modification time
32 33 34 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 32 def mtime entry.time end |
#mtime=(value) ⇒ Object
Set modification time
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 38 def mtime=(value) unless value.is_a?(Time) raise ArgumentError, "mtime must be a Time object" end entry.header.last_mod_time = dos_time(value) entry.header.last_mod_date = dos_date(value) @modified = true end |
#reset_modified ⇒ Object
Reset modified flag
98 99 100 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 98 def reset_modified @modified = false end |
#to_h ⇒ Hash
Get all metadata as a hash
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 104 def to_h { name: entry.name, comment: comment, mtime: mtime, unix_permissions: , size: entry.size, compressed_size: entry.compressed_size, crc: entry.crc, directory: entry.directory?, } end |
#unix_permissions ⇒ Integer
Get Unix permissions
51 52 53 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 51 def entry.unix_perms end |
#unix_permissions=(perms) ⇒ Object
Set Unix permissions
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 57 def (perms) unless perms.is_a?(Integer) raise ArgumentError, "permissions must be an integer" end unless (0..0o777).cover?(perms) raise ArgumentError, "permissions out of range" end entry.unix_perms = perms @modified = true end |