From: Robert Klemme Date: 2006-08-09T00:10:11+09:00 Subject: Re: Goto in Ruby? On 08.08.2006 16:47, aidy wrote: > I have a simple web GUI that I would like to read a file and enter data > into > > This is my class > > class Form > def initialize > @filename = "search.txt" > end > > def enter_data > read_in_test_data.each { |x| > line = x.chomp > #need to log testId > next if line.upcase.include? 'TESTID' > next if line.upcase == 'ADDRESS:' > $ie.text_field(:name, 'Address1').set(line) > $ie.text_field(:name, 'Address2').set(line) > $ie.text_field(:name, 'Address3').set(line) > $ie.text_field(:name, 'Address4').set(line) > $ie.text_field(:name, 'Address5').set(line) > $ie.text_field(:name, 'Address6').set(line) > $ie.text_field(:name, 'Address7').set(line) > } > 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 > > > > this is an example of the file I am reading > > *********************************************** TESTID_10 > Address: > 30 Choyce Close > Atherstone > Warwickshire > Country: > GB > Search-Results: > 20 > *********************************************** TESTID_20 > Address: > Hamilton Chartered Surveyors > Aidy Street > Bath > Country: > GB > Search-Results: > 1 > *********************************************** TESTID_30 > > > Sometimes the address can be upto 1..7 lines. What I am looking for is > something like a goto > statement, that when 'Country:' is found a different field can be > filled in e.g.($ie.text_field(:name, 'Ctry1').set(line). > > Thanks for the help > > Cheers > > Aidy > Use a CASE statement for this. case line.upcase when 'ADDRESS:' $ie.text_field(:name, 'Address1').set(line) $ie.text_field(:name, 'Address2').set(line) $ie.text_field(:name, 'Address3').set(line) $ie.text_field(:name, 'Address4').set(line) $ie.text_field(:name, 'Address5').set(line) $ie.text_field(:name, 'Address6').set(line) $ie.text_field(:name, 'Address7').set(line) when 'TESTID' # ... else # raise or what? end You can as well create more complex but flexible mechanisms (e.g. look up a lambda in a Hash) but whether it's worth the effort depends on your needs. HTH Kind regards robert