Class: Pubmedly::Pubmed

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

Overview

The Pubmed class is the main entry point for the gem. It is initialized with an NCBI API key and exposes methods for searching and fetching articles.

Examples:

pubmed = Pubmedly::Pubmed.new("my_api_key")
pubmed.search("cancer")    # returns an array of Pubmed IDs
pubmed.fetch(37194105)     # returns an array of Articles
pubmed.articles("cancer")  # returns an array of Articles

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Pubmed

Returns a new instance of Pubmed.



15
16
17
# File 'lib/pubmedly/pubmed.rb', line 15

def initialize(api_key)
  @client = Client.new(api_key)
end

Instance Method Details

#articles(term, **kwargs) ⇒ Object



27
28
29
# File 'lib/pubmedly/pubmed.rb', line 27

def articles(term, **kwargs)
  fetch(search(term, **kwargs), **kwargs)
end

#fetchObject



23
24
25
# File 'lib/pubmedly/pubmed.rb', line 23

def fetch(...)
  Parsers::Response.new(@client.fetch(...)).articles
end

#searchObject



19
20
21
# File 'lib/pubmedly/pubmed.rb', line 19

def search(...)
  Parsers::Response.new(@client.search(...)).ids
end