Class: Etna::Clients::Magma::UpdateAttributesFromCsvWorkflowSingleModel::Row
- Inherits:
-
RowBase
- Object
- RowBase
- Etna::Clients::Magma::UpdateAttributesFromCsvWorkflowSingleModel::Row
- Defined in:
- lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb
Instance Attribute Summary collapse
-
#record_name ⇒ Object
readonly
Returns the value of attribute record_name.
Instance Method Summary collapse
-
#initialize(raw, model_name, workflow) ⇒ Row
constructor
A new instance of Row.
- #to_h ⇒ Object
Methods inherited from RowBase
#attribute_is_json?, #nil_or_empty?, #stripped_value
Constructor Details
#initialize(raw, model_name, workflow) ⇒ Row
Returns a new instance of Row.
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 218 def initialize(raw, model_name, workflow) # Assumes CSV includes a column header to identify the attribute_name # Assumes index 0 is the record_name @raw = raw @model_name = model_name @workflow = workflow @record_name = @raw[0] raise "Invalid record name: \"#{record_name}\"." if nil_or_empty?(record_name) @record_name.strip! end |
Instance Attribute Details
#record_name ⇒ Object (readonly)
Returns the value of attribute record_name.
216 217 218 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 216 def record_name @record_name end |
Instance Method Details
#to_h ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 231 def to_h # Row can be converted to a hash, where keys are attribute_names and the # values come from the CSV # {attribute_name: attribute_value} {}.tap do |attributes| row_hash = @raw.to_h row_keys = row_hash.keys row_keys[1..row_keys.length - 1].each do |attribute_name| raise "Invalid attribute name: \"#{attribute_name}\"." if nil_or_empty?(attribute_name) attribute_name_clean = attribute_name.strip raise "Invalid attribute \"#{attribute_name_clean}\" for model #{@model_name}." unless attribute = @workflow.find_attribute(@model_name, attribute_name_clean) stripped = stripped_value(attribute, @raw[attribute_name]) unless @workflow.hole_value.nil? next if stripped == @workflow.hole_value end attributes[attribute_name_clean] = stripped end end end |