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

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.

<% @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

Anurag P. 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs