jeudi 11 mars 2021

Find Specific value of hash using ruby

I am trying to extract the value of the skuPartNumber from the below hash

{:error_code=>0, :data=>{"@odata.context"=>"https://graph.microsoft.com/v1.0/$metadata#users('xyz.yxz@domain.com')/licenseDetails", "value"=>[{"id"=>"88sGumHGlkiNvM0ZAFLCmUmPksW6EvdIraMNdDo2AdU", "skuId"=>"c5928f49-12ba-48f7-ada3-0d743a3601d5", "skuPartNumber"=>"SKUPartName1", "servicePlans"=>[{"servicePlanId"=>"da792a53-cbc0-4184-a10d-e544dd34b3c1", "servicePlanName"=>"ONEDRIVE_BASIC", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"2bdbaf8f-738f-4ac7-9234-3c3ee2ce7d0f", "servicePlanName"=>"VISIOONLINE", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"113feb6c-3fe4-4440-bddc-54d774bf0318", "servicePlanName"=>"EXCHANGE_S_FOUNDATION", "provisioningStatus"=>"PendingProvisioning", "appliesTo"=>"Company"}, {"servicePlanId"=>"663a804f-1c30-4ff0-9915-9db84f0d1cea", "servicePlanName"=>"VISIO_CLIENT_SUBSCRIPTION", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}]}, {"id"=>"88sGumHGlkiNvM0ZAFLCmZK4DfPpB-lHg3yAcn9G_T0", "skuId"=>"f30db892-07e9-47e9-837c-80727f46fd3d", "skuPartNumber"=>"SKUPartName2", "servicePlans"=>[{"servicePlanId"=>"113feb6c-3fe4-4440-bddc-54d774bf0318", "servicePlanName"=>"EXCHANGE_S_FOUNDATION", "provisioningStatus"=>"PendingProvisioning", "appliesTo"=>"Company"}, {"servicePlanId"=>"17ab22cd-a0b3-4536-910a-cb6eb12696c0", "servicePlanName"=>"DYN365_CDS_VIRAL", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}, {"servicePlanId"=>"50e68c76-46c6-4674-81f9-75456511b170", "servicePlanName"=>"FLOW_P2_VIRAL", "provisioningStatus"=>"Success", "appliesTo"=>"Company"}]}]}}

However, I tried using result[:data]['value']['skuPartNumber'] and result in the error.

How can extract the skuPartNumber where the SkuPartNumber is equal to "skuPartName2" from the above hash.

I can extract values with

result[:data]['value'][0]['skuPartNumber']

But would like to get the result based on specific value by providing skuPartNumber

Any help would be helpful.

Thanks

Aucun commentaire:

Enregistrer un commentaire