lib/map_fields/mapping.rb in map_fields-2.0.0.beta vs lib/map_fields/mapping.rb in map_fields-2.0.0.beta2
- old
+ new
@@ -3,20 +3,29 @@
def initialize(mapping, fields)
@mapping = mapping
@fields = fields
@mapping = mapping.each_with_object({}){ |arr, hash|
- key = arr[0].to_i
- value = arr[1].to_i
+ key = arr[1].blank? ? nil : arr[1].to_i
+ next if key.nil?
+ value = arr[0].blank? ? nil : arr[0].to_i
hash[key] = value
hash[@fields[key]] = value
hash[field_to_symbol(@fields[key])] = value
}
end
def [](index)
@mapping[index]
+ end
+
+ def is_mapped?(key)
+ @mapping.has_key?(key)
+ end
+
+ def selected_mapping(column)
+ @mapping.find{|k, v| return k if v == column && k.is_a?(Numeric) }
end
private
def field_to_symbol(field)
field.to_s.downcase.gsub(/[^a-z0-9]+/, '_').to_sym