ruby on rails - Erase Blank Json Loop -
I have a rail backend that receives JSON (when it is parsed):
= "gtc: mediawiki-xid =" gtc: mediawiki-xid = "gtc: mediawiki-xid =" gtc: basically what I want to do, in every way (Such as magazine or book), if all the other attributes keys are empty except like , then do not save that array key / value. So in my example, the magazine will be in the array, but will be removed as a book (because the value of both the attributes and the title is empty. I know that I can loop through something ( The list has been parsed before JSON):
list.each do | l | if l ["type"] == "magazine" if l ["value"] empty? # Then terminate this notice
but this is not very repetitive and clear. How can I improve it?
This can be used to idle unwanted lines to do so. You only remove the values Can remove the blank, and count the remaining values ... make sure that 'type' is one of them ...
list.reject! {| Item> item.values.reject (& amp;: blank?) Size & lt; 2 & amp; amp; amp; item ['type'] .present?}
reject and !
... gives a new hash while th e !
The method modifies it in place.
Comments
Post a Comment