Module: Chem::NCBI::ESearch

Extended by:
Chem::NetUtils
Defined in:
lib/chem/utils/net.rb

Overview

EInfo module

Constant Summary collapse

ESearchURI =
EUtilsURI + 'esearch.fcgi?'

Class Method Summary collapse

Methods included from Chem::NetUtils

http_get

Class Method Details

.search(params) ⇒ Object


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/chem/utils/net.rb', line 85

def self.search(params)
  result = {}
  uri = ESearchURI + params.collect{|key, value| key.to_s + "=" + CGI.escape(value.to_s)}.join("&")
  doc = http_get(uri)
  xml = REXML::Document.new(doc)
  raise "Error no result" unless xml.elements["eSearchResult/ERROR"].nil?

  result[:count]     = xml.elements["eSearchResult/Count"   ].text.to_i
  result[:retmax]   = xml.elements["eSearchResult/RetMax"  ].text.to_i
  result[:retstart] = xml.elements["eSearchResult/RetStart"].text.to_i
  
  result[:id_list] = list = []
  xml.elements.each("eSearchResult/IdList/Id") do |element|
    list << element.text.to_i
  end
  result
end