Check empty? of variable for Case/When

I have this:

I don't understand what you mean, can you be more explicit?

Colin

sorry..: P I meant this:

I have a record saved in the @collection variable
i.e. @collection = Collection.find(1)

I'm using nokogiri parser to add content of certain tag in the
collection into a new Article..
it happen sometimes that a field of the article is not available in
the collection..so I need to check before to "case" if it's not empty

So I have for istance:

Collection {name:string, title_tag:string, content_tag:string,
author_tag:string, ... }
Article{title:string,content:text,author:string, ... }

in the parser i want to add (dynamically) the collections tags
associated to Articles field

I'm not sure that each of the Collection field_tag is given.. and
before to do

Case 'TAG'
   When 'TAGNAME'

I'd want to check if the tag_field attribute is empty or not

I guess something like this:

   case child.name
        *unless @collection.location_tag.empty?*
         when @collection.location_tag
           @article.location = child.content
        *unless @collection.content_tag.empty?*
         when @collection.content_tag
           @article.content = child.content
        *unless @collection.docno_tag.empty?*
         when @collection.docno_tag
           @article.docno = child.content
        *unless @collection.date_tag.empty?*
         when @collection.date_tag
           temp_date = child.content
     end

but I hope exists a better way to do that instead using "unless" (I'm
not even sure it works..)

did i make it clearer? hope so.. :slight_smile:
thx

The most obvious thing that comes to mind is that if "child.name"
isn't empty, it's never going to much an empty tag attribute...

sorry..: P I meant this:

I have a record saved in the @collection variable
i.e. @collection = Collection.find(1)

I'm using nokogiri parser to add content of certain tag in the
collection into a new Article..
it happen sometimes that a field of the article is not available in
the collection..so I need to check before to "case" if it's not empty

So I have for istance:

Collection {name:string, title_tag:string, content_tag:string,
author_tag:string, ... }
Article{title:string,content:text,author:string, ... }

in the parser i want to add (dynamically) the collections tags
associated to Articles field

I'm not sure that each of the Collection field_tag is given.. and
before to do

Case 'TAG'
When 'TAGNAME'

I'd want to check if the tag_field attribute is empty or not

I guess something like this:

case child.name
*unless @collection.location_tag.empty?*

You don't need to test for empty? because if it is empty it will never
match in the 'when' (unless child.name is also empty which presumably
it is not)

Colin

Thanks, in this way is much easier :smiley:
Merry xmas btw :wink: