reverse engineering: "property[name=steps] > array"

D

Dan Thomas

Hi,

I'm new to Ruby, I've inherited some code for my job, and I'm trying to
understand it.

In the config.ru file, "sinatra/base" and "nokogiri" are required, and
then there is this line, which I understand:

$script = File.read("public/script2.xml")
@xml = Nokogiri::XML($script)

then it loads index.erb, and there is this line, which I need help with:

<% @xml.search("property[name=steps] > array").children.each do |step|
%>

I understand that we're going to loop through all of the property tags
with a name attribute = "steps".

later in that loop is this:

<%step.search("property[name=preDialogues] > array").children.each do
|dialogue|%>


So, looking at the first line, could each "step" be thought of as a node
in the xml? Then in the second line, are we looping through property
tags, inside of each step node, with attributes name="preDialogues"? Is
my explanation correct, here?

And if so, what is " > array" doing?

Thank you.
 
D

Dan Thomas

Anurag Priyam wrote in post #977094:
<% @xml.search("property[name=steps] > array").children.each do |step|
%>

I understand that we're going to loop through all of the property tags
with a name attribute = "steps".

If you have a look at [1], you are actually looping through all the
'array' elements, that are child of the 'property' element with the
attribute 'name' set to 'steps'.

[1] http://www.w3.org/TR/CSS2/selector.html

Cool! thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top