>From your comment it looks like I may need to understand why I would need
to assign values  return is already part of the text so my assumption is
that I just have to .to_sym it.  However, if I have to assign and deliver
something that would change quite a bit.

Clarification.

The desired resulting line is:
 ele.send_keys('Student One', :return, 'Student Two', :return)
Basically "'Student One', :return, 'Student Two', :return" is parsed to
result in itself except with the symbols understood as symbol type.

In the original:
x[0] == 'Student One'
', ' is added since it is not the last element
x[1] == 'return' output as x[1].to_sym which adds the : itself.
', ' is added since it is not the last element

Pattern repeats.

Mat, your idea has made the :return do what it is supposed to but now I'm
unable to get the text to output.  All that is coming out is the symbols
even though puts on the text line shows it should be displaying in the
following:
(I added .to_s even though I shouldn't have to just to be sure the type
hadn't changed.)

     items = text.split(/,\s?/)
      ele.send_keys(*items.map {|x|
      case x
        when /^.*'.*/ then $1.to_s+', '; puts 'hit a quote'   #
"'Student One'" => "Student One" (puts shows is hit but text not
displaying on screen)
        when /^:(.*)$/ then $1.to_sym    # ":return"       => :return
(outputting but requires comma?)
        else $1.to_s                                   #return unknowns as is 
(nothing should hit this)
      end
    })


Is it because the commas are stripped?  I tried adding them back in with +
' , ' on the to_sym line but received the error, 'undefined method `+' for
:return:Symbol'

I also am unsure how the case structure can detect if the element is 'last'
so that it doesn't add the comma on the last element.

On 23 November 2011 04:54, Matt Jones <[email protected]> wrote:

>
>
> On Nov 22, 4:00 pm, Julie <[email protected]> wrote:
> > Hello,
> >
> > I'm fairly new to Ruby, cucumber, and WebDriver and ran into what
> > seems to be a Ruby issue. It doesn't seem to be handling my .intern
> > or .to_sym in this mock-up inline form, ele.send_keys(x[i],
> > x[i].intern, x[i], x[i].intern)
> >
> > I tried both intern and to_sym with the same result, as expected.
> >
> > I'm trying to parse a string and output a string with symbol
> > parameter.
> >
> > Input string: 'Student One', :return, 'Student Two', :return
> > Output: ele.send_keys('Student One', :return, 'Student Two', :return)
> >
> > def fill_in(field_name,text)
> > #    ele = Find.Element(find_locator(:text_field,field_name))
> > #    ele.clear
> > #The above correctly obtains the text:
> > #   'Student One', :return, 'Student Two', :return
> > #Therefore, hard code to test:
> >    text = "'Student One', :return, 'Student Two', :return"
> >    items = text.split(/,\s?/)
> >    ele.send_keys(items.each_index {|x|
> >      next if x % 2 == 1
> >      if (x<items.size-1) then items[x] + ', ' else items[x] end
> >                 items[x+1].intern
> >     })
>
> Couple problems here:
>
> - each_index returns the original array. You're not assigning any new
> values to it, so of course .intern isn't having any effect.
>
> - not sure exactly what you're doing with the +', ' there, but I
> suspect you really want Ruby's "splat" operator. It takes an array and
> fills in the arguments to the method with each element (simplified
> description). Your code would end up looking like:
>
>
>   items = text.split(/,\s?/)
>   ele.send_keys(*items.map {|x|
>     case x
>     when /^'(.*)'$/ then $1        # "'Student One'" => "Student One"
>     when /^:(.*)$/ then $1.to_sym  # ":return"       => :return
>     end
>    })
>
> --Matt Jones
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to