How do I rewrite this populating @subcategories_urls_array
which is like "Fibonacci sequence in Ruby (recursion)".
Do I use a condition to check if there are no more '.group_title'
CSS-selectors to stop the recursion, or could it be done with a flag variable that counts cycles?
def main
=begin
=end
@job_section_url = find_job_section_url()
write_header_to_file()
@groups_urls_array = describe_groups(@job_section_url)
@subcategories_urls_array = Array.new
@groups_urls_array.each do |group_url|
@subcategories_urls_array << describe_groups(group_url)
end #each
@subcategories_urls_array.flatten!
end #main
def describe_groups(job_section_url)
=begin
Parse a page into an array of groups URLs.
=end
# @looking_for_a_job_string = '%D0%98%D1%89%D1%83+%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D1%83'
@groups_urls_array = Array.new
@page = open(job_section_url, 'Cookie' => 'city=3')
@doc = Nokogiri::HTML(@page)
@nodeset = @doc.css('.group_title')[0..-2]
@nodeset.each do |a|
@group_url = CGI.escape(a['href']).gsub('%2F', '/')
@group_url = URI.join(DOMAIN_URL, @group_url).to_s
@groups_urls_array << @group_url
end #each
@groups_urls_array
end #describe_groups
And do I really need this to implement?