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
readonly
Lookup column name for CSV.
-
#ignore_empty ⇒ Object
readonly
Returns the value of attribute ignore_empty.
-
#named_range ⇒ String
readonly
Named range that column exists in.
- #no_match_translation ⇒ Translation readonly
-
#translations ⇒ List<Translation>
readonly
What sort of data needs to be generated.
Instance Method Summary collapse
-
#initialize(column, named_range: Cure::Extraction.default_named_range, options: {}) ⇒ Candidate
constructor
A new instance of Candidate.
-
#perform(source_value, row_ctx) ⇒ String?
Transforms the existing value.
- #with_no_match_translation(no_match_translation) ⇒ Object
- #with_translations(translations) ⇒ Object
Methods included from Log
#log_debug, #log_error, #log_info, #log_trace, #log_warn
Methods included from Helpers::ObjectHelpers
Constructor Details
#initialize(column, named_range: Cure::Extraction.default_named_range, options: {}) ⇒ Candidate
Returns a new instance of Candidate.
33 34 35 36 37 38 39 40 |
# File 'lib/cure/transformation/candidate.rb', line 33 def initialize(column, named_range: Cure::Extraction.default_named_range, options: {}) @column = column @named_range = named_range @ignore_empty = .fetch(:ignore_empty, false) @translations = [] @no_match_translation = nil end |
Instance Attribute Details
#column ⇒ String (readonly)
Lookup column name for CSV.
22 23 24 |
# File 'lib/cure/transformation/candidate.rb', line 22 def column @column end |
#ignore_empty ⇒ Object (readonly)
Returns the value of attribute ignore_empty.
31 32 33 |
# File 'lib/cure/transformation/candidate.rb', line 31 def ignore_empty @ignore_empty end |
#named_range ⇒ String (readonly)
Named range that column exists in
18 19 20 |
# File 'lib/cure/transformation/candidate.rb', line 18 def named_range @named_range end |
#no_match_translation ⇒ Translation (readonly)
29 30 31 |
# File 'lib/cure/transformation/candidate.rb', line 29 def no_match_translation @no_match_translation end |
#translations ⇒ List<Translation> (readonly)
What sort of data needs to be generated.
26 27 28 |
# File 'lib/cure/transformation/candidate.rb', line 26 def translations @translations end |
Instance Method Details
#perform(source_value, row_ctx) ⇒ String?
Transforms the existing value
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cure/transformation/candidate.rb', line 46 def perform(source_value, row_ctx) value = source_value @translations.each do |translation| temp = translation.extract(value, row_ctx) value = temp if temp end if value == source_value && @no_match_translation log_trace("No translation made for #{value} [#{source_value}]") value = @no_match_translation.extract(source_value, row_ctx) log_trace("Translated to #{value} from [#{source_value}]") end value end |
#with_no_match_translation(no_match_translation) ⇒ Object
68 69 70 71 |
# File 'lib/cure/transformation/candidate.rb', line 68 def with_no_match_translation(no_match_translation) @no_match_translation = no_match_translation self end |
#with_translations(translations) ⇒ Object
63 64 65 66 |
# File 'lib/cure/transformation/candidate.rb', line 63 def with_translations(translations) @translations = translations self end |