Class: I18nContextGenerator::ContextExtractor::ExtractionResult

Inherits:
Data
  • Object
show all
Defined in:
lib/i18n_context_generator/context_extractor/extraction_result.rb

Overview

Result for a single translation key, including evidence, review state, and run-local provider/cache telemetry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, text:, description:, **attributes) ⇒ ExtractionResult

Returns a new instance of ExtractionResult.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 13

def initialize(key:, text:, description:, **attributes)
  defaults = {
    source_file: nil,
    ui_element: nil,
    tone: nil,
    max_length: nil,
    locations: [],
    changed_locations: [],
    changed_location_groups: [],
    translation_key: key,
    changed_translation_locations: [],
    confidence: nil,
    ambiguity_reason: nil,
    cache_hit: false,
    request_count: 0,
    input_tokens: 0,
    output_tokens: 0,
    retries: 0,
    status: attributes[:error] ? :error : :success,
    error: nil
  }
  values = defaults.merge(attributes)
  values[:status] = values[:status].to_sym if values[:status].respond_to?(:to_sym)
  super(key: key, text: text, description: description, **values)
end

Instance Attribute Details

#ambiguity_reasonObject (readonly)

Returns the value of attribute ambiguity_reason

Returns:

  • (Object)

    the current value of ambiguity_reason



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def ambiguity_reason
  @ambiguity_reason
end

#cache_hitObject (readonly)

Returns the value of attribute cache_hit

Returns:

  • (Object)

    the current value of cache_hit



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def cache_hit
  @cache_hit
end

#changed_location_groupsObject (readonly)

Returns the value of attribute changed_location_groups

Returns:

  • (Object)

    the current value of changed_location_groups



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def changed_location_groups
  @changed_location_groups
end

#changed_locationsObject (readonly)

Returns the value of attribute changed_locations

Returns:

  • (Object)

    the current value of changed_locations



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def changed_locations
  @changed_locations
end

#changed_translation_locationsObject (readonly)

Returns the value of attribute changed_translation_locations

Returns:

  • (Object)

    the current value of changed_translation_locations



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def changed_translation_locations
  @changed_translation_locations
end

#confidenceObject (readonly)

Returns the value of attribute confidence

Returns:

  • (Object)

    the current value of confidence



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def confidence
  @confidence
end

#descriptionObject (readonly)

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def description
  @description
end

#errorObject (readonly)

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def error
  @error
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def input_tokens
  @input_tokens
end

#keyObject (readonly)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def key
  @key
end

#locationsObject (readonly)

Returns the value of attribute locations

Returns:

  • (Object)

    the current value of locations



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def locations
  @locations
end

#max_lengthObject (readonly)

Returns the value of attribute max_length

Returns:

  • (Object)

    the current value of max_length



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def max_length
  @max_length
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def output_tokens
  @output_tokens
end

#request_countObject (readonly)

Returns the value of attribute request_count

Returns:

  • (Object)

    the current value of request_count



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def request_count
  @request_count
end

#retriesObject (readonly)

Returns the value of attribute retries

Returns:

  • (Object)

    the current value of retries



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def retries
  @retries
end

#source_fileObject (readonly)

Returns the value of attribute source_file

Returns:

  • (Object)

    the current value of source_file



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def source_file
  @source_file
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def text
  @text
end

#toneObject (readonly)

Returns the value of attribute tone

Returns:

  • (Object)

    the current value of tone



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def tone
  @tone
end

#translation_keyObject (readonly)

Returns the value of attribute translation_key

Returns:

  • (Object)

    the current value of translation_key



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def translation_key
  @translation_key
end

#ui_elementObject (readonly)

Returns the value of attribute ui_element

Returns:

  • (Object)

    the current value of ui_element



7
8
9
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 7

def ui_element
  @ui_element
end

Instance Method Details

#actionable?Boolean

Returns:

  • (Boolean)


39
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 39

def actionable? = status == :success && error.nil? && !description.to_s.strip.empty?

#to_hObject



41
42
43
# File 'lib/i18n_context_generator/context_extractor/extraction_result.rb', line 41

def to_h
  members.to_h { |member| [member, public_send(member)] }
end