lib/google_custom_search.rb
##
# Transform an array of Google search results (XML parsed by REXML) into
# a more useful format.
#
Transform an array of Google search results (XML parsed by REXML) into
a more useful format.
Transform an array of Google search results ( XML parsed by REXML ) into a more useful format .
def parse_results(results)
    out = []
    results = [results] if results.is_a?(Hash) 
    results.each do |r|
      out << Result.new(
        r['U'],                               
        r['T'].try(:sub, / \[[^\]]*\]$/, ''), 
        r['S'].try(:gsub, '<br>', '')         
      )
    end
    out
  end
def parse_results ( results ) out = [ ] results = [ results ] if results . is_a? ( Hash ) results . each do | r | out << Result . new ( r [ 'U' ] , r [ 'T' ] . try ( :sub , / \[ [^ \] ]* \] $ / , '' ) , r [ 'S' ] . try ( :gsub , '<br>' , '' ) ) end out end
Transform an array of Google search results (XML parsed by REXML) into
a more useful format.
Transform an array of Google search results ( XML parsed by REXML ) into a more useful format .
# no array if only one result # url # title # desciption
results
<not_specific>