Class: ExtractTtc::Models::ExtractionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/extract_ttc/models/extraction_result.rb

Overview

Represents the result of a font extraction operation

This model encapsulates the outcome of extracting fonts from a TTC file, including the list of output files created, success status, and any errors encountered during the process.

This is an immutable value object with methods to query success/failure status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_files: [], success: true, errors: []) ⇒ ExtractionResult

Initialize a new extraction result

Parameters:

  • output_files (Array<String>) (defaults to: [])

    Array of output file paths created

  • success (Boolean) (defaults to: true)

    Whether the extraction was successful

  • errors (Array<String>) (defaults to: [])

    Array of error messages (empty if successful)



20
21
22
23
24
# File 'lib/extract_ttc/models/extraction_result.rb', line 20

def initialize(output_files: [], success: true, errors: [])
  @output_files = output_files.freeze
  @success = success
  @errors = errors.freeze
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/extract_ttc/models/extraction_result.rb', line 13

def errors
  @errors
end

#output_filesObject (readonly)

Returns the value of attribute output_files.



13
14
15
# File 'lib/extract_ttc/models/extraction_result.rb', line 13

def output_files
  @output_files
end

#successObject (readonly)

Returns the value of attribute success.



13
14
15
# File 'lib/extract_ttc/models/extraction_result.rb', line 13

def success
  @success
end

Instance Method Details

#add_error(message) ⇒ ExtractionResult

Add an error message to the result

This creates a new ExtractionResult with the error added, as the object is immutable.

Parameters:

  • message (String)

    The error message to add

Returns:



47
48
49
50
51
52
53
# File 'lib/extract_ttc/models/extraction_result.rb', line 47

def add_error(message)
  self.class.new(
    output_files: @output_files.dup,
    success: false,
    errors: @errors.dup << message,
  )
end

#failure?Boolean

Check if the extraction failed

Returns:

  • (Boolean)

    true if failed, false otherwise



36
37
38
# File 'lib/extract_ttc/models/extraction_result.rb', line 36

def failure?
  !@success
end

#success?Boolean

Check if the extraction was successful

Returns:

  • (Boolean)

    true if successful, false otherwise



29
30
31
# File 'lib/extract_ttc/models/extraction_result.rb', line 29

def success?
  @success
end