Could someone help me with this block of code I have:
doc.xpath("//script[@type='text/javascript']/text()").each do |text|
if text.content =~ /more_options_on_polling/
price1 = text.to_s.scan(/\"(formatted_total_price)\":\"(.+?)\"/).uniq
description = text.to_s.scan(/\"(ticket_desc)\":\"(.+?)\"/).uniq
price = price1 + description
testing = price1.map{|a| { a[0] => a[1] } }
desc = description.map{|a| { a[0] => a[1] } }
respond_to do |format|
format.json { render :json => {:testing => testing,
:desc => desc }}
end
end
When I check the 'desc', It shows the following info:
"desc": [
{
"ticket_desc": "Later Owl Ticket"
},
{
"ticket_desc": "Later Owl Ticket+Collector Ticket @ extra £4.95 per ticket"
},
{
"ticket_desc": "Later Owl + Chance For VIP Upgrade"
},
{
"ticket_desc": "VIP Ticket"
},
{
"ticket_desc": "VIP Ticket + Collector Ticket @ extra £4.95 per ticket"
},
{
"ticket_desc": "Skydeck Package"
},
{
"ticket_desc": "5 Person Skydeck Table"
},
{
"ticket_desc": "7 Person Skydeck Table"
},
{
"ticket_desc": "10 Person Skydeck Table"
}
]
What I want is to exclude any ticket descriptions with a + symbol. So the desired output would be:
"desc": [
{
"ticket_desc": "Later Owl Ticket"
},
{
"ticket_desc": "VIP Ticket"
},
{
"ticket_desc": "Skydeck Package"
},
{
"ticket_desc": "5 Person Skydeck Table"
},
{
"ticket_desc": "7 Person Skydeck Table"
},
{
"ticket_desc": "10 Person Skydeck Table"
}
]
I'm working on this using Rails, and I am rendering it in the view using JavaScript/Ajax. If you have any suggestions on how to handle this, please share them :)
Here's the Ajax snippet being used:
for (var i = 0; i < json.testing.length; i++) {
var section = json.testing[i].formatted_total_price;
var desc = json.desc[i].ticket_desc;