[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Validating multiple contents

Bala Krishnan

10/17/2008 5:15:00 AM

Hi
If we want to validate result page with single text content we will
use

ie.text.include?(" Particular content ")

suppose if i want to validate page with multiple content like

German rails
NGINX
how to use ruby for this validation?
--
Posted via http://www.ruby-....

3 Answers

Roger Pack

10/17/2008 6:17:00 AM

0

Bala Krishnan wrote:
> Hi
> If we want to validate result page with single text content we will
> use
>
> ie.text.include?(" Particular content ")
>
> suppose if i want to validate page with multiple content like
>
> German rails
> NGINX
> how to use ruby for this validation?

maybe something like
ie.text.include?(" Particular content ") || ie.text.include?('ich
bien') ?
--
Posted via http://www.ruby-....

Matthew Moss

10/17/2008 1:50:00 PM

0


On Oct 17, 2008, at 12:15 AM, Bala Krishnan wrote:

> Hi
> If we want to validate result page with single text content we will
> use
>
> ie.text.include?(" Particular content ")
>
> suppose if i want to validate page with multiple content like
>
> German rails
> NGINX
> how to use ruby for this validation?


["German rails", "NGINX"].any? { |str| ie.text.include?(str) }

This will return true if any of the strings are found in ie.text.
Replace any? with all? to return true only if all of the strings are
found.



Henrik Nyh

10/18/2008 8:31:00 AM

0

On Fri, Oct 17, 2008 at 3:50 PM, Matthew Moss <matt@moss.name> wrote:
>
> On Oct 17, 2008, at 12:15 AM, Bala Krishnan wrote:
>
>> Hi
>> If we want to validate result page with single text content we will
>> use
>>
>> ie.text.include?(" Particular content ")
>>
>> suppose if i want to validate page with multiple content like
>>
>> German rails
>> NGINX
>> how to use ruby for this validation?
>
>
> ["German rails", "NGINX"].any? { |str| ie.text.include?(str) }
>
> This will return true if any of the strings are found in ie.text. Replace
> any? with all? to return true only if all of the strings are found.

More obscure but kind of cute:

Regexp.union("German rails", "NGINX").match(ie.text)

Regexp.union creates a regexp that matches any of the parts. They're
regexp-escaped, too.