Class: Pubmedly::Parsers::Response
- Inherits:
-
Object
- Object
- Pubmedly::Parsers::Response
- Defined in:
- lib/pubmedly/parsers/response.rb
Overview
The Response class parses XML from the NCBI eutils API’s responses.
Instance Method Summary collapse
- #articles ⇒ Object
- #count ⇒ Object
- #ids ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
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
#articles ⇒ Object
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 |
#count ⇒ Object
13 14 15 |
# File 'lib/pubmedly/parsers/response.rb', line 13 def count @xml.xpath(".//Count")&.text.to_i end |
#ids ⇒ Object
17 18 19 |
# File 'lib/pubmedly/parsers/response.rb', line 17 def ids @xml.xpath(".//Id")&.map(&:text)&.map(&:to_i)&.to_a end |