Class: Omnizip::Models::ConversionResult
- Inherits:
-
Object
- Object
- Omnizip::Models::ConversionResult
- Defined in:
- lib/omnizip/models/conversion_result.rb
Overview
Model for format conversion results
Instance Attribute Summary collapse
-
#compression_ratio ⇒ Object
readonly
Returns the value of attribute compression_ratio.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#entry_count ⇒ Object
readonly
Returns the value of attribute entry_count.
-
#source_format ⇒ Object
readonly
Returns the value of attribute source_format.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
-
#source_size ⇒ Object
readonly
Returns the value of attribute source_size.
-
#target_format ⇒ Object
readonly
Returns the value of attribute target_format.
-
#target_path ⇒ Object
readonly
Returns the value of attribute target_path.
-
#target_size ⇒ Object
readonly
Returns the value of attribute target_size.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(source_path:, target_path:, source_format:, target_format:, source_size:, target_size:, duration:, entry_count:, warnings: []) ⇒ ConversionResult
constructor
Initialize conversion result.
-
#larger? ⇒ Boolean
Check if conversion resulted in larger file.
-
#processing_speed ⇒ Float
Get average processing speed.
-
#size_ratio ⇒ Float
Get size ratio.
-
#size_reduction ⇒ Float
Get size reduction percentage.
-
#smaller? ⇒ Boolean
Check if conversion resulted in smaller file.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_s ⇒ String
Format as human-readable string.
-
#warnings? ⇒ Boolean
Check if there were warnings.
Constructor Details
#initialize(source_path:, target_path:, source_format:, target_format:, source_size:, target_size:, duration:, entry_count:, warnings: []) ⇒ ConversionResult
Initialize conversion result
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omnizip/models/conversion_result.rb', line 21 def initialize( source_path:, target_path:, source_format:, target_format:, source_size:, target_size:, duration:, entry_count:, warnings: [] ) @source_path = source_path @target_path = target_path @source_format = source_format @target_format = target_format @source_size = source_size @target_size = target_size @duration = duration @entry_count = entry_count @warnings = warnings @compression_ratio = calculate_compression_ratio end |
Instance Attribute Details
#compression_ratio ⇒ Object (readonly)
Returns the value of attribute compression_ratio.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def compression_ratio @compression_ratio end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def duration @duration end |
#entry_count ⇒ Object (readonly)
Returns the value of attribute entry_count.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def entry_count @entry_count end |
#source_format ⇒ Object (readonly)
Returns the value of attribute source_format.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def source_format @source_format end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def source_path @source_path end |
#source_size ⇒ Object (readonly)
Returns the value of attribute source_size.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def source_size @source_size end |
#target_format ⇒ Object (readonly)
Returns the value of attribute target_format.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def target_format @target_format end |
#target_path ⇒ Object (readonly)
Returns the value of attribute target_path.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def target_path @target_path end |
#target_size ⇒ Object (readonly)
Returns the value of attribute target_size.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def target_size @target_size end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
7 8 9 |
# File 'lib/omnizip/models/conversion_result.rb', line 7 def warnings @warnings end |
Instance Method Details
#larger? ⇒ Boolean
Check if conversion resulted in larger file
68 69 70 |
# File 'lib/omnizip/models/conversion_result.rb', line 68 def larger? target_size > source_size end |
#processing_speed ⇒ Float
Get average processing speed
80 81 82 83 84 85 86 87 |
# File 'lib/omnizip/models/conversion_result.rb', line 80 def processing_speed return 0.0 if duration.zero? || source_size.zero? speed = source_size / duration / 1_048_576.0 rounded = speed.round(2) # Return actual speed if rounding would give 0 but speed is positive rounded.zero? && speed.positive? ? speed : rounded end |
#size_ratio ⇒ Float
Get size ratio
54 55 56 57 58 |
# File 'lib/omnizip/models/conversion_result.rb', line 54 def size_ratio return 0.0 if source_size.zero? (target_size.to_f / source_size * 100).round(2) end |
#size_reduction ⇒ Float
Get size reduction percentage
46 47 48 49 50 |
# File 'lib/omnizip/models/conversion_result.rb', line 46 def size_reduction return 0.0 if source_size.zero? ((source_size - target_size).to_f / source_size * 100).round(2) end |
#smaller? ⇒ Boolean
Check if conversion resulted in smaller file
62 63 64 |
# File 'lib/omnizip/models/conversion_result.rb', line 62 def smaller? target_size < source_size end |
#to_h ⇒ Hash
Convert to hash
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/omnizip/models/conversion_result.rb', line 91 def to_h { source_path: source_path, target_path: target_path, source_format: source_format, target_format: target_format, source_size: source_size, target_size: target_size, size_reduction: size_reduction, size_ratio: size_ratio, duration: duration, entry_count: entry_count, processing_speed: processing_speed, warnings: warnings, } end |
#to_s ⇒ String
Format as human-readable string
110 111 112 113 114 |
# File 'lib/omnizip/models/conversion_result.rb', line 110 def to_s "Converted #{source_path} (#{format_size(source_size)}) to " \ "#{target_path} (#{format_size(target_size)}) in #{duration.round(2)}s. " \ "#{size_reduction.positive? ? "Saved #{size_reduction.to_i}%" : "Increased #{(-size_reduction).to_i}%"}" end |
#warnings? ⇒ Boolean
Check if there were warnings
74 75 76 |
# File 'lib/omnizip/models/conversion_result.rb', line 74 def warnings? !warnings.empty? end |