Module: Chem::NCBI::ESummary

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

Constant Summary collapse

ESummaryURI =
EUtilsURI + 'esummary.fcgi?'

Class Method Summary collapse

Methods included from Chem::NetUtils

http_get

Class Method Details

.get(params) ⇒ Object



147
148
149
150
# File 'lib/chem/utils/net.rb', line 147

def self.get(params)
  uri = ESummaryURI + params.collect{|key, value| key.to_s + "=" + value.to_s}.join("&")
  http_get(uri)
end

.get_parsed(params) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/chem/utils/net.rb', line 152

def self.get_parsed(params)
  tree = {}
  xml = REXML::Document.new(get(params))
  xml.elements.each("eSummaryResult/DocSum/Item") do |element|
    tree[element.attributes["Name"]] =
      case element.attributes["Type"]
      when "String"
        element.text
      when "Integer"
        element.text.to_i
      when "Date"
        element.text
      when "List"
        ary = []
        element.elements.each("Item"){|el|
        ary << case el.attributes["Type"]
               when "String"
                 el.text
               when "Integer"
                 el.text.to_i
               else
                 ""
               end
      }
        ary
      end
  end
  tree
end