Class: Cure::Transformation::Candidate

Inherits:
Object
  • Object
show all
Includes:
Helpers::ObjectHelpers, Log
Defined in:
lib/cure/transformation/candidate.rb

Overview

Per row, we will have a candidate for each transformation that needs to be made

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log_debug, #log_error, #log_info, #log_warn

Methods included from Helpers::ObjectHelpers

#attributes=, #from_hash, #from_json

Constructor Details

#initializeCandidate

Returns a new instance of Candidate.



30
31
32
33
# File 'lib/cure/transformation/candidate.rb', line 30

def initialize
  @translations = []
  @named_range = "default"
end

Instance Attribute Details

#columnString

Lookup column name for CSV.

Returns:

  • (String)


21
22
23
# File 'lib/cure/transformation/candidate.rb', line 21

def column
  @column
end

#named_rangeString

Named range that column exists in

Returns:

  • (String)


17
18
19
# File 'lib/cure/transformation/candidate.rb', line 17

def named_range
  @named_range
end

#no_match_translationTranslation

Returns:



28
29
30
# File 'lib/cure/transformation/candidate.rb', line 28

def no_match_translation
  @no_match_translation
end

#translationsList<Translation>

What sort of data needs to be generated.

Returns:



25
26
27
# File 'lib/cure/transformation/candidate.rb', line 25

def translations
  @translations
end

Instance Method Details

#perform(source_value) ⇒ String

Transforms the existing value

Parameters:

  • source_value (String)

Returns:

  • (String)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cure/transformation/candidate.rb', line 38

def perform(source_value)
  # log_debug("Performing substitution for [#{@column}] with [#{@translations.length}] translations")
  value = source_value

  @translations.each do |translation|
    temp = translation.extract(value)
    value = temp if temp
  end

  if value == source_value
    log_debug("No translation made for #{value} [#{source_value}]")
    value = @no_match_translation&.extract(source_value)
    log_debug("Translated to #{value} from [#{source_value}]")
  end

  value
end