Forum: Ruby Validating multiple contents

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6adf629498efa0ef169ffe532e410ca2?d=identicon&s=25 Bala Krishnan (sbalabala)
on 2008-10-17 07:15
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?
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-10-17 08:17
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') ?
A61ecce13ed142622f24a5ca3a123922?d=identicon&s=25 Matthew Moss (Guest)
on 2008-10-17 15:51
(Received via mailing list)
On Oct 17, 2008, at 12:15 AM, Bala Krishnan wrote:

>  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.
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik --- (malesca)
on 2008-10-18 10:32
(Received via mailing list)
On Fri, Oct 17, 2008 at 3:50 PM, Matthew Moss <matt@moss.name> wrote:
>>
>>                   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.
This topic is locked and can not be replied to.