lib/google_translate.rb in google-translate-0.6.9 vs lib/google_translate.rb in google-translate-0.7.0

- old
+ new

@@ -96,44 +96,48 @@ response = {} open(URI.escape(request)) do |stream| content = stream.read - from_languages = collect_languages content, 0, 'sllangdropdown', 'sl', 'old_sl' - to_languages = collect_languages content, 1, 'tllangdropdown', 'tl', 'old_tl' + from_languages = collect_languages content, 0, 'sl', 'gt-sl' + to_languages = collect_languages content, 1, 'tl', 'gt-tl' response[:from_languages] = from_languages response[:to_languages] = to_languages end response end - def collect_languages buffer, index, class_name, tag_name, tag_id + def collect_languages buffer, index, tag_name, tag_id languages = [] spaces = '\s?' quote = '(\s|\'|")?' - class_part = "class#{spaces}=#{spaces}#{quote}#{class_name}#{quote}" - name_part = "name#{spaces}=#{spaces}#{quote}#{tag_name}#{quote}" + id_part = "id#{spaces}=#{spaces}#{quote}#{tag_id}#{quote}" + name_part = "name#{spaces}=#{spaces}#{quote}#{tag_name}#{quote}" tabindex_part = "tabindex#{spaces}=#{spaces}#{quote}0#{quote}" - re1 = buffer.split(%r{<select#{spaces}#{class_part}#{spaces}#{name_part}#{spaces}#{id_part}#{spaces}#{tabindex_part}#{spaces}>(.*)?</select>}).select{|x| x =~ %r{<option} } + phrase = "#{spaces}#{id_part}#{spaces}#{name_part}#{spaces}#{tabindex_part}#{spaces}" + re1 = buffer.split(%r{<select#{phrase}>(.*)?</select>}).select{|x| x =~ %r{<option} } + + stopper = "</select></div>" + text = re1[index] if index == 0 - pos = text.index('</select><span class=langselect') + pos = text.index(stopper) text = text[0..pos] end re2 = /<option(\s*)value="([a-z|A-Z|-]*)">([a-z|A-Z|\(|\)|\s]*)<\/option>/ matches = text.gsub(/selected/i, '').squeeze.scan(re2) matches.each do |m| - languages << Language.new(m[2], m[1]) + languages << Language.new(m[2], m[1]) end languages end end