Class: SafeImage::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/safe_image/result.rb

Overview

Public image-operation return value. ‘output`/`output_format` are nil for metadata-only probes; image-producing operations always include them. `tier` records the concrete execution tier (for example :native_encode, :jpegtran_lossless or :jpegtran_fallback_reencode) so non-fatal degradation is observable without parsing the backend label.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend

Returns:

  • (Object)

    the current value of backend



13
14
15
# File 'lib/safe_image/result.rb', line 13

def backend
  @backend
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms

Returns:

  • (Object)

    the current value of duration_ms



13
14
15
# File 'lib/safe_image/result.rb', line 13

def duration_ms
  @duration_ms
end

#filesizeObject (readonly)

Returns the value of attribute filesize

Returns:

  • (Object)

    the current value of filesize



13
14
15
# File 'lib/safe_image/result.rb', line 13

def filesize
  @filesize
end

#heightObject (readonly)

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



13
14
15
# File 'lib/safe_image/result.rb', line 13

def height
  @height
end

#inputObject (readonly)

Returns the value of attribute input

Returns:

  • (Object)

    the current value of input



13
14
15
# File 'lib/safe_image/result.rb', line 13

def input
  @input
end

#input_formatObject (readonly)

Returns the value of attribute input_format

Returns:

  • (Object)

    the current value of input_format



13
14
15
# File 'lib/safe_image/result.rb', line 13

def input_format
  @input_format
end

#optimizerObject (readonly)

Returns the value of attribute optimizer

Returns:

  • (Object)

    the current value of optimizer



13
14
15
# File 'lib/safe_image/result.rb', line 13

def optimizer
  @optimizer
end

#outputObject (readonly)

Returns the value of attribute output

Returns:

  • (Object)

    the current value of output



13
14
15
# File 'lib/safe_image/result.rb', line 13

def output
  @output
end

#output_formatObject (readonly)

Returns the value of attribute output_format

Returns:

  • (Object)

    the current value of output_format



13
14
15
# File 'lib/safe_image/result.rb', line 13

def output_format
  @output_format
end

#tierObject (readonly)

Returns the value of attribute tier

Returns:

  • (Object)

    the current value of tier



13
14
15
# File 'lib/safe_image/result.rb', line 13

def tier
  @tier
end

#widthObject (readonly)

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



13
14
15
# File 'lib/safe_image/result.rb', line 13

def width
  @width
end

Class Method Details

.build(input:, output: nil, input_format:, output_format: nil, width:, height:, backend:, duration_ms:, filesize: nil, optimizer: nil, encoder: nil, tier: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/safe_image/result.rb', line 27

def self.build(
  input:,
  output: nil,
  input_format:,
  output_format: nil,
  width:,
  height:,
  backend:,
  duration_ms:,
  filesize: nil,
  optimizer: nil,
  encoder: nil,
  tier: nil
)
  new(
    input: input.to_s,
    output: output&.to_s,
    input_format: input_format,
    output_format: output_format,
    width: width,
    height: height,
    filesize: filesize || result_filesize(input, output),
    backend: BackendLabel.build(backend, encoder: encoder),
    duration_ms: duration_ms,
    optimizer: optimizer,
    tier: tier
  )
end

.metadata(input:, input_format:, width:, height:, backend:, duration_ms:) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/safe_image/result.rb', line 56

def self.(input:, input_format:, width:, height:, backend:, duration_ms:)
  build(
    input: input,
    input_format: input_format,
    width: width,
    height: height,
    filesize: File.size(input),
    backend: backend,
    duration_ms: duration_ms,
    tier: :metadata
  )
end

.result_filesize(input, output) ⇒ Object



69
70
71
72
# File 'lib/safe_image/result.rb', line 69

def self.result_filesize(input, output)
  path = output || input
  path ? File.size(path) : nil
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


74
# File 'lib/safe_image/result.rb', line 74

def success? = true