From: Daniel N Date: 2006-08-09T21:39:49+09:00 Subject: Re: Goto in Ruby? ------=_Part_37473_19425489.1155127185722 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/9/06, aidy wrote: > > > Robert Klemme wrote: > > > You probably should state more clearly what you need. Then we can come > > up with better suggestions. > > This is an example of a file I am reading. > > ********************************************** TESTID_10 > Address: > 30 Choyce Close > Atherstone > Country: > GB > Search-Results: > 20 > EXPECTED-RESULT: > *********************************************** TESTID_20 > Address: > Hamilton Chartered Surveyors > Aidy Street > Bath > Country: > GB > Search-Results: > 1 > EXPECTED-RESULT: > *********************************************** TESTID_30 > > The GUI looks something like this > > Address 1 ___________ > Address 2 ___________ > Address 3 ___________ > Address 4 ___________ > > etc upto 7 > > However in some cases I will have one or two lines to enter in the > address, > other times 5,6 or 7 > > There are also two other fields: Country and Serach Results > > this is the code > > class Form > > def initialize > @filename = "search.txt" > end > > def enter_data > y = 11 > read_in_test_data.each { |x| > line = x.chomp > p line > if line.upcase != 'ADDRESS:' and !line.upcase.include? 'TESTID' > name = 'A' + y.to_s > > next if line.upcase == 'COUNTRY:' > $ie.text_field(:name, 'C1').set(line) > next if line.upcase =='SEARCH-RESULTS:' > $ie.text_field(:name, 'NoResults').set(line) > break if line.upcase =='EXPECTED-RESULT:' > > $ie.text_field(:name, name).set(line) > y = y + 1 > end > } > end > > def read_in_test_data > #check if file exists and give date of last change > File.readlines(@filename, "\n" ) > end > private:read_in_test_data > > end > > My 'logic' is when the file is read if we do not see ADDRESS: or TESTID > then we must be at the point to enter the address > > y = 11 > if line.upcase != 'ADDRESS:' and !line.upcase.include? 'TESTID' > name = 'A' + y.to_s > $ie.text_field(:name, name).set(line) > y = y + 1 > > the object names for addresses start from A11, hence the iterator. > > However if I hit 'COUNTRY:', I need to put the country in the country > field (hence the next if [which in both cases will be GB), then > the search result in the SEARCH-RESULTS: field. > > Cheers > > Aidy > > > This may not be the nicest solution, but it is flexible and it might get help you come up with a better solution. You can have any fields with any number of values. Below is the code. If you copy and paste it into a ruby file it should run with some output. Cheers @test_data = <