ruby - compare array of hashes and print expected & actual results -


i have 2 array of hashes:

actual = [{"column_name"=>"noninterestincome", "column_data_type"=>"number"},  {"column_name"=>"noninterestexpense", "column_data_type"=>"varchar"},  {"column_name"=>"transactiondate", "column_data_type"=>"timestamp"},  {"column_name"=>"updatedate", "column_data_type"=>"timestamp"}] expected = [{"column_name"=>"noninterestincome", "column_data_type"=>"number"},  {"column_name"=>"noninterestexpense", "column_data_type"=>"number"},  {"column_name"=>"transactiondate", "column_data_type"=>"number"},  {"column_name"=>"updatedate", "column_data_type"=>"timestamp"}] 

i need compare these 2 hashes , find out ones column_data_type differs.

to compare can directly use:

diff = actual -   expected 

this print output as:

{"column_name"=>"noninterestexpense", "column_data_type"=>"varchar"} {"column_name"=>"transactiondate", "column_data_type"=>"timestamp"} 

my expected output in result want print actual , expected datatype, means datatypes missing `column_name' both actual , expected array of hashes, like:

{"column_name"=>"noninterestexpense", "expected_column_data_type"=>"number", "actual_column_data_type" => "varchar"} {"column_name"=>"transactiondate", "expected_column_data_type"=>"number","actual_column_data_type" => "timestamp" } 

(expected - actual).   concat(actual - expected).   group_by { |column| column['column_name'] }.   map |name, (expected, actual)|     {       'column_name'               => name,       'expected_column_data_type' => expected['column_data_type'],       'actual_column_data_type'   => actual['column_data_type'],     }   end 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -