lib/tailwind_dsl/etl/element.rb in tailwind_dsl-0.0.8 vs lib/tailwind_dsl/etl/element.rb in tailwind_dsl-0.0.9
- old
+ new
@@ -16,17 +16,35 @@
raise guard if value.nil? && guard
value || default
end
+ # Map data to a class
+ #
+ # @param klass [Class] The class to map to
+ # @param data [Hash, Class] The data to map can be hash, an instance of the class or nil
def map_to(klass, data)
return nil if data.nil?
return data if data.is_a?(klass)
return klass.new(**data) if data.is_a?(Hash)
puts "Data of type: #{data.class} cannot be converted to #{klass}"
nil
+ end
+
+ # Add data onto an array
+ #
+ # @param target_list [Array] The array to add to
+ # @param data [Hash, Class] The data to add can be hash or an instance of the class. Nil data will not be added
+ def add_to_list(klass, target_list, data)
+ item = map_to(klass, data)
+
+ return nil if item.nil?
+
+ target_list << item
+
+ item
end
end
end
end