Class: Omnizip::Metadata::EntryMetadata
- Inherits:
-
Object
- Object
- Omnizip::Metadata::EntryMetadata
- Includes:
- Entry
- 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.
- #entry_directory? ⇒ Boolean
- #entry_mtime ⇒ Object
- #entry_name ⇒ Object
- #entry_size ⇒ Object
-
#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
19 20 21 22 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 19 def initialize(entry) @entry = entry @modified = false end |
Instance Attribute Details
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
10 11 12 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 10 def entry @entry end |
Instance Method Details
#attributes ⇒ Integer
Get external attributes
80 81 82 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 80 def attributes entry.header.external_attributes end |
#attributes=(value) ⇒ Object
Set external attributes
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 86 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
26 27 28 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 26 def comment entry.comment end |
#comment=(value) ⇒ Object
Set entry comment
32 33 34 35 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 32 def comment=(value) entry.comment = value.to_s @modified = true end |
#entry_directory? ⇒ Boolean
13 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 13 def entry_directory? = entry.directory? |
#entry_mtime ⇒ Object
15 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 15 def entry_mtime = entry.time |
#entry_name ⇒ Object
12 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 12 def entry_name = entry.name |
#entry_size ⇒ Object
14 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 14 def entry_size = entry.size |
#modified? ⇒ Boolean
Check if metadata has been modified
100 101 102 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 100 def modified? @modified end |
#mtime ⇒ Time
Get modification time
39 40 41 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 39 def mtime entry.time end |
#mtime=(value) ⇒ Object
Set modification time
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 45 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
105 106 107 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 105 def reset_modified @modified = false end |
#to_h ⇒ Hash
Get all metadata as a hash
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 111 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
58 59 60 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 58 def entry.unix_perms end |
#unix_permissions=(perms) ⇒ Object
Set Unix permissions
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/omnizip/metadata/entry_metadata.rb', line 64 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 |