我想使用Ruby MAP来获取数据:
PAYMENT_TYPE_TO_CURRENCY_AND_COUNTRY_MAPPING = {
zimpler: { 'EUR' => ['FI'], 'SEK' => ['SE'] },
qiwi: { 'EUR' => ['RU', 'KZ'], 'RUB' => ['RU'], 'KZT' => ['KZ'], 'USD' => ['UA'] },
payu: { 'CZK' => ['CZ'], 'PLN' => ['PL']},
entercash: { 'EUR' => ['AT', 'DE', 'FI'], 'SEK' => ['SE'] },
carulla: { 'USD' => ['CO'] }
}
我想使用MAP中的上述数据创建存根:
GirogateRequestBuilder::PAYMENT_TYPE_TO_CURRENCY_AND_COUNTRY_MAPPING.keys.each do |payment_method|
stub_request(:post, /.*/).
with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<payment_transaction>\n
<transaction_type>#{payment_method.key}</transaction_type>\n
<transaction_id>/.*/</transaction_id>\n
<usage>New iPad</usage>\n
<currency>#{payment_method.get here currency}</currency>\n
<billing_address>\n
<first_name>Barney</first_name>\n
<country>#{payment_method.get here country}</country>\n
<state/>\n
</billing_address>\n
:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'Cache-Control'=>'no-cache', 'Content-Type'=>'application/xml'})
.to_return(status: 200, body: successful_response_file)
end
如何从地图上获取正确的值?
答案 0 :(得分:0)
只需使用PAYMENT_TYPE_TO_CURRENCY_AND_COUNTRY_MAPPING.each do |key, value|
:
PAYMENT_TYPE_TO_CURRENCY_AND_COUNTRY_MAPPING.each do |key, value|
# key = :zimpler
# value = { 'EUR' => ['FI'], 'SEK' => ['SE'] }