Class: Cure::Transformation::Candidate
- Inherits:
-
Object
- Object
- Cure::Transformation::Candidate
- 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
-
#column ⇒ String
Lookup column name for CSV.
-
#named_range ⇒ String
Named range that column exists in.
- #no_match_translation ⇒ Translation
-
#translations ⇒ List<Translation>
What sort of data needs to be generated.
Instance Method Summary collapse
-
#initialize ⇒ Candidate
constructor
A new instance of Candidate.
-
#perform(source_value) ⇒ String
Transforms the existing value.
Methods included from Log
#log_debug, #log_error, #log_info, #log_warn
Methods included from Helpers::ObjectHelpers
#attributes=, #from_hash, #from_json
Constructor Details
#initialize ⇒ Candidate
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
#column ⇒ String
Lookup column name for CSV.
21 22 23 |
# File 'lib/cure/transformation/candidate.rb', line 21 def column @column end |
#named_range ⇒ String
Named range that column exists in
17 18 19 |
# File 'lib/cure/transformation/candidate.rb', line 17 def named_range @named_range end |
#no_match_translation ⇒ Translation
28 29 30 |
# File 'lib/cure/transformation/candidate.rb', line 28 def no_match_translation @no_match_translation end |
#translations ⇒ List<Translation>
What sort of data needs to be generated.
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
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 |