Class: TopSecret::Text::BatchResult

Inherits:
Object
  • Object
show all
Includes:
Mapping
Defined in:
lib/top_secret/text/batch_result.rb

Overview

Holds the result of a batch redaction operation on multiple messages. Contains a global mapping that ensures consistent labeling across all messages and a collection of individual input/output pairs.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mapping

#categories, #method_missing, #respond_to_missing?, #safe?, #sensitive?

Constructor Details

#initialize(mapping: {}, items: []) ⇒ BatchResult

Creates a new BatchResult instance

Parameters:

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

    Global mapping of redaction labels to original values

  • items (Array<Item>) (defaults to: [])

    Array of input/output pairs



21
22
23
24
# File 'lib/top_secret/text/batch_result.rb', line 21

def initialize(mapping: {}, items: [])
  @mapping = mapping
  @items = items
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TopSecret::Mapping

Instance Attribute Details

#itemsArray<Item> (readonly)

Returns Array of input/output pairs for each processed message.

Returns:

  • (Array<Item>)

    Array of input/output pairs for each processed message



15
16
17
# File 'lib/top_secret/text/batch_result.rb', line 15

def items
  @items
end

#mappingHash (readonly)

Returns Global mapping of redaction labels to original values across all messages.

Returns:

  • (Hash)

    Global mapping of redaction labels to original values across all messages



12
13
14
# File 'lib/top_secret/text/batch_result.rb', line 12

def mapping
  @mapping
end

Class Method Details

.from_messages(messages, custom_filters: [], **filters) ⇒ BatchResult

Creates a BatchResult from multiple messages with consistent global labeling

Parameters:

  • messages (Array<String>)

    Array of text messages to filter

  • custom_filters (Array) (defaults to: [])

    Additional custom filters to apply

  • filters (Hash)

    Optional filters to override defaults (only valid filter keys accepted)

Returns:

  • (BatchResult)

    Contains global mapping and array of Result objects with individual mappings

Raises:

  • (ArgumentError)

    If invalid filter keys are provided



33
34
35
36
37
38
39
# File 'lib/top_secret/text/batch_result.rb', line 33

def self.from_messages(messages, custom_filters: [], **filters)
  individual_results = TopSecret::Text::Result.from_messages(messages, custom_filters:, **filters)
  mapping = TopSecret::Text::GlobalMapping.from_results(individual_results)
  items = TopSecret::Text::Result.with_global_labels(individual_results, mapping)

  Text::BatchResult.new(mapping:, items:)
end