Class: Pubmedly::Parsers::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pubmedly/parsers/response.rb

Overview

The Response class parses XML from the NCBI eutils API’s responses.

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



9
10
11
# File 'lib/pubmedly/parsers/response.rb', line 9

def initialize(response)
  @xml = Nokogiri::XML(response.body)
end

Instance Method Details

#articlesObject



21
22
23
24
25
# File 'lib/pubmedly/parsers/response.rb', line 21

def articles
  @xml.xpath(".//PubmedArticle").map do |article_xml|
    Pubmedly::Parsers::Article.new(article_xml)
  end
end

#countObject



13
14
15
# File 'lib/pubmedly/parsers/response.rb', line 13

def count
  @xml.xpath(".//Count")&.text.to_i
end

#idsObject



17
18
19
# File 'lib/pubmedly/parsers/response.rb', line 17

def ids
  @xml.xpath(".//Id")&.map(&:text)&.map(&:to_i)&.to_a
end