0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehasemodule MappingsHelper
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase def sort_mapping_list(collection)
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase hash = {}
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase collection.each_with_index do |mapping, i|
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase if mapping.symbol_mappings.empty?
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase set_empty_mapping!(hash, mapping, "empty#{i}")
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase else
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase add_symbol_mappings!(hash, mapping)
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase end
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase end
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase hash
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehase end
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase private
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase def set_empty_mapping!(hash, mapping, name)
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase hash[name] = [{mapping: mapping, target: ''}]
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase hash
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase end
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase def add_symbol_mappings!(hash, mapping)
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase mapping.symbol_mappings.each do |symbol_mapping|
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase sym = mapping.source.to_s.to_sym
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase hash[sym] ||= []
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase hash[sym] << {mapping: mapping, target: symbol_mapping.target}
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase end
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase hash
e1d2fd86f76c899ca9cc37b6dc892a1410b53470Tim Reddehase end
0d3763fcd43f738899afcf8699b0e02b833c8132Tim Reddehaseend