ruby - Merging two arrays of capybara elements -


this similar something posted yesterday got mixed had in front of me. have 2 arrays need merging same index value have capybara elements opposed strings , integers.

example

@returned_names = page.all('#results > table.result > tbody > tr.data:first-of-type > td') @returned_yobs = page.all('#results > table.result > tbody > tr.data:nth-child(2) > td')  # returns @returned_names = [#<capybara::element tag="td">, #<capybara::element tag="td">, #<capybara::element tag="td">] @returned_yobs = [#<capybara::element tag="td">, #<capybara::element tag="td">, #<capybara::element tag="td">] 

so based on yesterdays answer merge these together, matching index values should do

@collection = @returned_names.zip(@returned_yobs).map { |r| r.join(' ') } # returns ["#<capybara::node::element:0x000000038c50e8> #<capybara::node::element:0x000000036fadf8>",  "#<capybara::node::element:0x000000038c50c0> #<capybara::node::element:0x000000036fadd0>",  "#<capybara::node::element:0x000000038c5020> #<capybara::node::element:0x000000036fada8>"] 

which far looks doing right thing. need convert array of text values, when do

@collection.map { |t| t.text } 

i error

undefined method `text' #<string:0x00000001938310> 

i'm guessing cant map here don't have enumerable object @ stage?

is there way @collection enumerable object can map text values ?

any appreciated

thanks

array#join converts each object (i.e. node) string. should work:

@returned_names.zip(@returned_yobs).map { |name, yob| "#{name.text} #{yob.text}" } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -