Class: Uniword::Batch::UpdateMetadataStage

Inherits:
ProcessingStage show all
Defined in:
lib/uniword/batch/stages/update_metadata_stage.rb

Overview

Processing stage that updates document metadata.

Responsibility: Update document properties and metadata. Single Responsibility - only handles metadata updates.

Examples:

Use in pipeline

stage = UpdateMetadataStage.new(
  update_author: true,
  update_modified_date: true,
  author: 'John Doe'
)
document = stage.process(document, context)

Instance Attribute Summary

Attributes inherited from ProcessingStage

#enabled, #options

Instance Method Summary collapse

Methods inherited from ProcessingStage

#enabled?, #name

Constructor Details

#initialize(options = {}) ⇒ UpdateMetadataStage

Initialize update metadata stage

Parameters:

  • options (Hash) (defaults to: {})

    Stage options

Options Hash (options):

  • :update_author (Boolean)

    Update author

  • :update_modified_date (Boolean)

    Update modified date

  • :update_revision_number (Boolean)

    Update revision number

  • :author (String)

    Specific author name

  • :company (String)

    Company name

  • :title (String)

    Document title



27
28
29
30
31
32
33
34
35
# File 'lib/uniword/batch/stages/update_metadata_stage.rb', line 27

def initialize(options = {})
  super
  @update_author = options.fetch(:update_author, true)
  @update_modified_date = options.fetch(:update_modified_date, true)
  @update_revision_number = options.fetch(:update_revision_number, true)
  @author = options[:author]
  @company = options[:company]
  @title = options[:title]
end

Instance Method Details

#descriptionString

Get stage description

Returns:

  • (String)

    Description



55
56
57
# File 'lib/uniword/batch/stages/update_metadata_stage.rb', line 55

def description
  "Update document metadata"
end

#process(document, context = {}) ⇒ Document

Process document to update metadata

Parameters:

  • document (Document)

    Document to process

  • context (Hash) (defaults to: {})

    Processing context

Returns:

  • (Document)

    Processed document



42
43
44
45
46
47
48
49
50
# File 'lib/uniword/batch/stages/update_metadata_stage.rb', line 42

def process(document, context = {})
  log "Updating metadata in #{context[:filename]}"

  update_core_properties(document)
  update_extended_properties(document) if @company

  log "Metadata update complete"
  document
end