Class: Omnizip::Metadata::ArchiveMetadata
- Inherits:
-
Object
- Object
- Omnizip::Metadata::ArchiveMetadata
- Defined in:
- lib/omnizip/metadata/archive_metadata.rb
Overview
Model for archive-level metadata
Instance Attribute Summary collapse
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
Instance Method Summary collapse
-
#comment ⇒ String
Get archive comment.
-
#comment=(value) ⇒ Object
Set archive comment.
-
#compression_ratio ⇒ Float
Get compression ratio.
-
#created_at ⇒ Time?
Get creation date (approximated from first entry).
-
#directory_count ⇒ Integer
Get directory count.
-
#entry_count ⇒ Integer
Get entry count.
-
#file_count ⇒ Integer
Get file count (excluding directories).
-
#initialize(archive) ⇒ ArchiveMetadata
constructor
Initialize archive metadata.
-
#modified? ⇒ Boolean
Check if metadata has been modified.
-
#modified_at ⇒ Time?
Get modification date (from newest entry).
-
#reset_modified ⇒ Object
Reset modified flag.
-
#to_h ⇒ Hash
Get all metadata as a hash.
-
#total_compressed_size ⇒ Integer
Get total compressed size.
-
#total_size ⇒ Integer
Get total uncompressed size.
Constructor Details
#initialize(archive) ⇒ ArchiveMetadata
Initialize archive metadata
11 12 13 14 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 11 def initialize(archive) @archive = archive @modified = false end |
Instance Attribute Details
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
7 8 9 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 7 def archive @archive end |
Instance Method Details
#comment ⇒ String
Get archive comment
18 19 20 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 18 def comment archive.comment end |
#comment=(value) ⇒ Object
Set archive comment
24 25 26 27 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 24 def comment=(value) archive.comment = value.to_s @modified = true end |
#compression_ratio ⇒ Float
Get compression ratio
59 60 61 62 63 64 65 66 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 59 def compression_ratio return 0.0 if total_size.zero? ratio = 1.0 - (total_compressed_size.to_f / total_size) # Clamp ratio between 0.0 and 1.0 (compressed size can exceed # original size for small files or incompressible data) [[ratio, 0.0].max, 1.0].min end |
#created_at ⇒ Time?
Get creation date (approximated from first entry)
31 32 33 34 35 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 31 def created_at return nil if archive.entries.empty? archive.entries.map(&:time).min end |
#directory_count ⇒ Integer
Get directory count
82 83 84 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 82 def directory_count archive.entries.count(&:directory?) end |
#entry_count ⇒ Integer
Get entry count
70 71 72 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 70 def entry_count archive.entries.size end |
#file_count ⇒ Integer
Get file count (excluding directories)
76 77 78 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 76 def file_count archive.entries.count(&:file?) end |
#modified? ⇒ Boolean
Check if metadata has been modified
88 89 90 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 88 def modified? @modified end |
#modified_at ⇒ Time?
Get modification date (from newest entry)
39 40 41 42 43 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 39 def modified_at return nil if archive.entries.empty? archive.entries.map(&:time).max end |
#reset_modified ⇒ Object
Reset modified flag
93 94 95 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 93 def reset_modified @modified = false end |
#to_h ⇒ Hash
Get all metadata as a hash
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 99 def to_h { comment: comment, created_at: created_at, modified_at: modified_at, total_size: total_size, total_compressed_size: total_compressed_size, compression_ratio: compression_ratio, entry_count: entry_count, file_count: file_count, directory_count: directory_count, } end |
#total_compressed_size ⇒ Integer
Get total compressed size
53 54 55 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 53 def total_compressed_size archive.entries.sum(&:compressed_size) end |
#total_size ⇒ Integer
Get total uncompressed size
47 48 49 |
# File 'lib/omnizip/metadata/archive_metadata.rb', line 47 def total_size archive.entries.sum(&:size) end |