Class: Uniword::FormatConverter::ConversionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/format_converter.rb

Overview

Result object for conversion operations.

Explicitly reports what happened during conversion. No hidden state - all information is accessible.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ConversionResult

Initialize conversion result

Parameters:

  • attributes (Hash)

    Result attributes



204
205
206
207
208
209
210
211
212
213
214
# File 'lib/uniword/format_converter.rb', line 204

def initialize(attributes)
  @source = attributes[:source]
  @source_format = attributes[:source_format]
  @target = attributes[:target]
  @target_format = attributes[:target_format]
  @success = attributes[:success]
  @paragraphs_count = attributes[:paragraphs_count] || 0
  @tables_count = attributes[:tables_count] || 0
  @images_count = attributes[:images_count] || 0
  @error = attributes[:error]
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def error
  @error
end

#images_countObject (readonly)

Returns the value of attribute images_count.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def images_count
  @images_count
end

#paragraphs_countObject (readonly)

Returns the value of attribute paragraphs_count.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def paragraphs_count
  @paragraphs_count
end

#sourceObject (readonly)

Returns the value of attribute source.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def source
  @source
end

#source_formatObject (readonly)

Returns the value of attribute source_format.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def source_format
  @source_format
end

#successObject (readonly)

Returns the value of attribute success.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def success
  @success
end

#tables_countObject (readonly)

Returns the value of attribute tables_count.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def tables_count
  @tables_count
end

#targetObject (readonly)

Returns the value of attribute target.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def target
  @target
end

#target_formatObject (readonly)

Returns the value of attribute target_format.



197
198
199
# File 'lib/uniword/format_converter.rb', line 197

def target_format
  @target_format
end

Instance Method Details

#success?Boolean

Check if conversion succeeded

Returns:

  • (Boolean)

    true if successful



219
220
221
# File 'lib/uniword/format_converter.rb', line 219

def success?
  @success
end

#to_hHash

Get detailed result as hash

Returns:

  • (Hash)

    Result details



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/uniword/format_converter.rb', line 239

def to_h
  {
    source: source,
    source_format: source_format,
    target: target,
    target_format: target_format,
    success: success,
    paragraphs_count: paragraphs_count,
    tables_count: tables_count,
    images_count: images_count,
    error: error
  }
end

#to_sString

Get human-readable result summary

Returns:

  • (String)

    Conversion summary



226
227
228
229
230
231
232
233
234
# File 'lib/uniword/format_converter.rb', line 226

def to_s
  if success?
    "Conversion: #{source_format}#{target_format} " \
      "(#{paragraphs_count} paragraphs, #{tables_count} tables, " \
      "#{images_count} images) - SUCCESS"
  else
    "Conversion: #{source_format}#{target_format} - FAILED: #{error}"
  end
end