HELP-understandable error

Hello all,
here is my method lines 85-92:

def contenu(nb)
@titre = @page.css("tr")[nb.to_i].css("h2").css("a").text
@lieu = @page.css("tr")[nb.to_i].css("a").css("p")[0].text
@prix = @page.css("tr")[nb.to_i].css("span")[4].text
puts @titre
puts @lieu+'|'+@prix[0..-2]
puts '---'
end

···

----------------------
Here his call at line 95:

contenu(y)
----------------------
Here the error:
88:in 'contenu': undefined method 'text' for nil:NilClass
(NoMethodError)from 95:in '<main>'
----------------------
My question: why the price-line(prix) work differently of the two others
before her?
She works fine if i put a number, and don't work with the "nb" whithout
.to_i.
This may be a link with the character € (it's for that the -2 at line
90, because it show "?" instead).

If you are french, i am too, et mon anglais n'est pas assez avancé pour
tout comprendre en cette langue.

Thanks to you.

--
Posted via http://www.ruby-forum.com/.

looks like 'css("span")[4]' is returning nil
insert a line before line 88:
inspect @page.css("tr")[nb.to_i].css("span")

to see if the data matches what you expect

···

On Sat, Oct 26, 2013 at 9:33 PM, Romain Vass <lists@ruby-forum.com> wrote:

Hello all,
here is my method lines 85-92:

def contenu(nb)
@titre = @page.css("tr")[nb.to_i].css("h2").css("a").text
@lieu = @page.css("tr")[nb.to_i].css("a").css("p")[0].text
@prix = @page.css("tr")[nb.to_i].css("span")[4].text
puts @titre
puts @lieu+'|'+@prix[0..-2]
puts '---'
end
----------------------
Here his call at line 95:

contenu(y)
----------------------
Here the error:
88:in 'contenu': undefined method 'text' for nil:NilClass
(NoMethodError)from 95:in '<main>'
----------------------
My question: why the price-line(prix) work differently of the two others
before her?
She works fine if i put a number, and don't work with the "nb" whithout
.to_i.
This may be a link with the character € (it's for that the -2 at line
90, because it show "?" instead).

If you are french, i am too, et mon anglais n'est pas assez avancé pour
tout comprendre en cette langue.

Thanks to you.

--
Posted via http://www.ruby-forum.com/\.

D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:
in `inspect': wrong number of arguments(1 for 0) (ArgumentError)
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:in `contenu'
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:100:in `<main>'

···

--
Posted via http://www.ruby-forum.com/.

@page.css("tr")[nb.to_i].css("span").inspect
that make no error

···

--
Posted via http://www.ruby-forum.com/.

See in the file attached.

Attachments:
http://www.ruby-forum.com/attachment/8866/bug.txt

···

--
Posted via http://www.ruby-forum.com/.

Oh yes it was that, the element i will is the 4th not the 5th, i am so
stupid (because i know array start at 0).

Very much thanks to you, can i quote your name like helper in my
program?

···

--
Posted via http://www.ruby-forum.com/.

sorry,
@page.css("tr")[nb.to_i].css("span").inspect

···

On Sat, Oct 26, 2013 at 10:43 PM, Romain Vass <lists@ruby-forum.com> wrote:

D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:
in `inspect': wrong number of arguments(1 for 0) (ArgumentError)
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:92:in `contenu'
from D:/Documents and
Settings/Administrator/Desktop/jpe/JPE-Complet/JPE-C.rb:100:in `<main>'

--
Posted via http://www.ruby-forum.com/\.

it should print the object
from your code you should see an array of at least 4 items, since you are
trying to grab the fourth
If it is printing a list of less then 4 items, or is nil, thats the cause
of the error
the job then is to figure out why your input is not as you expect

···

On Sun, Oct 27, 2013 at 9:12 AM, Romain Vass <lists@ruby-forum.com> wrote:

@page.css("tr")[nb.to_i].css("span").inspect
that make no error

--
Posted via http://www.ruby-forum.com/\.

array indexes start at 0
the element at index 4 is the fifth

looking at the output, some of the rows have less then 5 elements, and that
is where you get the nil when using index 4

It appears that in all the output the last element is the same, so if you
just want
to grab the last element use an index of -1

···

On Sun, Oct 27, 2013 at 6:16 PM, Romain Vass <lists@ruby-forum.com> wrote:

See in the file attached.

Attachments:
http://www.ruby-forum.com/attachment/8866/bug.txt

--
Posted via http://www.ruby-forum.com/\.

sure, glad i could help

merci beaucoup :wink:

···

On Sun, Oct 27, 2013 at 7:02 PM, Romain Vass <lists@ruby-forum.com> wrote:

Oh yes it was that, the element i will is the 4th not the 5th, i am so
stupid (because i know array start at 0).

Very much thanks to you, can i quote your name like helper in my
program?

--
Posted via http://www.ruby-forum.com/\.