Class: CaTissue::ControlledValueFinder
- Inherits:
-
Object
- Object
- CaTissue::ControlledValueFinder
- Defined in:
- lib/catissue/database/controlled_value_finder.rb
Overview
Finds attribute controlled values.
Instance Method Summary collapse
-
#controlled_value(value) ⇒ Object
Returns the CV value for the given source value.
-
#initialize(attribute, file = nil) ⇒ ControlledValueFinder
constructor
Creates a new ControlledValueFinder for the given attribute.
Constructor Details
#initialize(attribute, file = nil) ⇒ ControlledValueFinder
Creates a new ControlledValueFinder for the given attribute. The optional YAML properties file name maps input values to controlled values.
9 10 11 12 |
# File 'lib/catissue/database/controlled_value_finder.rb', line 9 def initialize(attribute, file=nil) @attribute = attribute @remap_hash = load_controlled_value_hash(file) end |
Instance Method Details
#controlled_value(value) ⇒ Object
Returns the CV value for the given source value. If the value is remapped, then that value is returned. Otherwise, if the value is a standard CV, then the CV value is returned. Otherwise, a warning message is printed to the log and this method returns nil.
18 19 20 21 22 23 24 25 |
# File 'lib/catissue/database/controlled_value_finder.rb', line 18 def controlled_value(value) return if value.blank? remapped = remapped_controlled_value(value) return remapped if remapped cv = supported_controlled_value(value) logger.warn("#{@attribute} value '#{value}' ignored since it is not a recognized controlled value.") if cv.nil? cv.value if cv end |