pubmedly 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3ce515f0fc81d823f6685a8711ea61113003ff1417de4b51981ed130f7f1b074
4
+ data.tar.gz: 93feffd74c056084fee11e5bc75307ff9a91b5fc301da2082e36fb180b0da6fb
5
+ SHA512:
6
+ metadata.gz: e6bd4ef020f8e5f85d44843acd24170ae5d08b519944041b938055584e85fd92c1bb5674e457634eb4348caa7c9a113957fc2c01acaebb5242ca2179b37c55f8
7
+ data.tar.gz: e53587fd6bf4d3070fa79a6e46d7f8fc825cf6086271ce7d13401bf2444a44661d8565dd8b59c005d790affe6155d4edcc917aab330a721c894d361e33456bfd
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
7
+ SuggestExtensions: true
8
+ NewCops: enable
9
+
10
+ Gemspec/DevelopmentDependencies:
11
+ EnforcedStyle: gemspec
12
+
13
+ Layout/FirstHashElementIndentation:
14
+ Enabled: false
15
+
16
+ Layout/HashAlignment:
17
+ EnforcedColonStyle: table
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+
22
+ Metrics/ModuleLength:
23
+ Exclude:
24
+ - "spec/**/*"
25
+
26
+ RSpec/ExampleLength:
27
+ Enabled: False
28
+
29
+ RSpec/MultipleExpectations:
30
+ Enabled: False
31
+
32
+ Style/NumericLiterals:
33
+ Enabled: false
34
+
35
+ Style/StringLiterals:
36
+ Enabled: true
37
+ EnforcedStyle: double_quotes
38
+
39
+ Style/StringLiteralsInInterpolation:
40
+ Enabled: true
41
+ EnforcedStyle: double_quotes
42
+
43
+ Style/TrailingCommaInHashLiteral:
44
+ EnforcedStyleForMultiline: consistent_comma
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.2.0] - 2023-05-20
4
+
5
+ - Pubmed and Client classes
6
+ - Updated README
7
+ - Specs
8
+ - Convenience objects in console, @client and @pubmed
9
+ - Configure and obey Rubocop
10
+
11
+ ## [0.1.0] - 2023-04-08
12
+
13
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at robsimpsondev@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify gem dependencies in pubmedly.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pubmedly (0.2.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.4)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ byebug (11.1.3)
14
+ coderay (1.1.3)
15
+ crack (0.4.5)
16
+ rexml
17
+ diff-lcs (1.5.0)
18
+ ffi (1.15.5)
19
+ hashdiff (1.0.1)
20
+ json (2.6.3)
21
+ listen (3.8.0)
22
+ rb-fsevent (~> 0.10, >= 0.10.3)
23
+ rb-inotify (~> 0.9, >= 0.9.10)
24
+ method_source (1.0.0)
25
+ nokogiri (1.14.3-arm64-darwin)
26
+ racc (~> 1.4)
27
+ nokogiri (1.14.3-x86_64-linux)
28
+ racc (~> 1.4)
29
+ os (1.1.4)
30
+ parallel (1.22.1)
31
+ parser (3.2.2.0)
32
+ ast (~> 2.4.1)
33
+ pry (0.14.2)
34
+ coderay (~> 1.1)
35
+ method_source (~> 1.0)
36
+ pry-reload (0.3)
37
+ listen (~> 3.4)
38
+ public_suffix (5.0.1)
39
+ racc (1.6.2)
40
+ rainbow (3.1.1)
41
+ rake (13.0.6)
42
+ rb-fsevent (0.11.2)
43
+ rb-inotify (0.10.1)
44
+ ffi (~> 1.0)
45
+ regexp_parser (2.7.0)
46
+ rexml (3.2.5)
47
+ rspec (3.12.0)
48
+ rspec-core (~> 3.12.0)
49
+ rspec-expectations (~> 3.12.0)
50
+ rspec-mocks (~> 3.12.0)
51
+ rspec-core (3.12.1)
52
+ rspec-support (~> 3.12.0)
53
+ rspec-expectations (3.12.2)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.12.0)
56
+ rspec-mocks (3.12.5)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.12.0)
59
+ rspec-support (3.12.0)
60
+ rubocop (1.49.0)
61
+ json (~> 2.3)
62
+ parallel (~> 1.10)
63
+ parser (>= 3.2.0.0)
64
+ rainbow (>= 2.2.2, < 4.0)
65
+ regexp_parser (>= 1.8, < 3.0)
66
+ rexml (>= 3.2.5, < 4.0)
67
+ rubocop-ast (>= 1.28.0, < 2.0)
68
+ ruby-progressbar (~> 1.7)
69
+ unicode-display_width (>= 2.4.0, < 3.0)
70
+ rubocop-ast (1.28.0)
71
+ parser (>= 3.2.1.0)
72
+ rubocop-capybara (2.18.0)
73
+ rubocop (~> 1.41)
74
+ rubocop-factory_bot (2.23.1)
75
+ rubocop (~> 1.33)
76
+ rubocop-rake (0.6.0)
77
+ rubocop (~> 1.0)
78
+ rubocop-rspec (2.22.0)
79
+ rubocop (~> 1.33)
80
+ rubocop-capybara (~> 2.17)
81
+ rubocop-factory_bot (~> 2.22)
82
+ ruby-progressbar (1.13.0)
83
+ unicode-display_width (2.4.2)
84
+ vcr (6.1.0)
85
+ webmock (3.18.1)
86
+ addressable (>= 2.8.0)
87
+ crack (>= 0.3.2)
88
+ hashdiff (>= 0.4.0, < 2.0.0)
89
+
90
+ PLATFORMS
91
+ arm64-darwin-22
92
+ x86_64-linux
93
+
94
+ DEPENDENCIES
95
+ byebug
96
+ os
97
+ pry
98
+ pry-reload
99
+ pubmedly!
100
+ rake
101
+ rspec
102
+ rubocop
103
+ rubocop-rake
104
+ rubocop-rspec
105
+ vcr
106
+ webmock
107
+
108
+ BUNDLED WITH
109
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Rob Simpson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Pubmedly
2
+
3
+ **WIP**
4
+
5
+ This gem provides a `Pubmedly::Client` with methods that get data from the NCBI's [Pubmed database](https://pubmed.ncbi.nlm.nih.gov/) using their [eutils APIs](https://www.ncbi.nlm.nih.gov/books/NBK25499/).
6
+
7
+ Furthermore, this gem provides a `Pubmedly::Pubmed` class that makes interacting with the eutils APIs easier by parsing the XML responses into useful Ruby objects.
8
+
9
+ You will need an API key to use this gem; doing this is simple and described with context [here](https://www.ncbi.nlm.nih.gov/books/NBK25497/).
10
+
11
+ ## Installation
12
+
13
+ Requirements: Ruby.
14
+
15
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
16
+
17
+ Install the gem and add to the application's Gemfile by executing:
18
+
19
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
20
+
21
+ If bundler is not being used to manage dependencies, install the gem by executing:
22
+
23
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
24
+
25
+ ## Usage
26
+
27
+ `Pubmedly::Client` has methods synonymous with the NCBI's eutils API, and the raw web responses are returned with data in XML (default) or JSON.
28
+
29
+ ```ruby
30
+ client = Pubmedly::Client.new("<YOUR_NCBI_API_KEY>")
31
+ #<Pubmedly::Client:0x00000001089768d8 @api_key="<YOUR_NCBI_API_KEY>">
32
+
33
+ response = client.search("Bifidobacterium longum", retmax: 10)
34
+ #<Net::HTTPOK 200 OK readbody=true>
35
+
36
+ puts response.body
37
+ #<?xml version="1.0" encoding="UTF-8" ?>
38
+ #<!DOCTYPE eSearchResult PUBLIC "-//NLM//DTD esearch 20060628//EN" "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd">
39
+ #<eSearchResult><Count>2321</Count><RetMax>10</RetMax><RetStart>0</RetStart><IdList>
40
+ #<Id>37180228</Id>
41
+ #<Id>37176158</Id>
42
+ #<Id>37175970</Id>
43
+ #<Id>37174650</Id>
44
+ #<Id>37172455</Id>
45
+ # ...
46
+
47
+ response = client.fetch(37180228)
48
+ #<Net::HTTPOK 200 OK readbody=true>
49
+
50
+ puts response.body
51
+ #<?xml version="1.0" ?>
52
+ #<!DOCTYPE PubmedArticleSet PUBLIC "-//NLM//DTD PubMedArticle, 1st January 2023//EN" "https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_230101.dtd">
53
+ #<PubmedArticleSet>
54
+ # <PubmedArticle>
55
+ # <MedlineCitation Status="PubMed-not-MEDLINE" Owner="NLM" IndexingMethod="Automated">
56
+ # <PMID Version="1">37180228</PMID>
57
+ # ...
58
+ ```
59
+
60
+ `Pubmedly::Pubmed` wraps the NCBI API methods implemented in `Pubmedly::Client` to make the return types more useful.
61
+
62
+ ```ruby
63
+ pubmed = Pubmedly::Pubmed.new("<YOUR_NCBI_API_KEY>")
64
+ #<Pubmedly::Pubmed:0x0000000108a97d20 @client=#<Pubmedly::Client:0x0000000108a97c58 @api_key="<YOUR_NCBI_API_KEY>">>
65
+
66
+ ```
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. for convenience the console will initialize with `@client` and `@pubmed` objects if `NCBI_API_KEY` is defined in your environment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`.
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/robsimpsondev/pubmedly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/robsimpsondev/pubmedly/blob/main/CODE_OF_CONDUCT.md).
77
+
78
+ With write access to the `main` branch one can release a new version by updating the version number in `version.rb`, and running `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Versioning
81
+
82
+ This project uses [Semantic Versioning](https://semver.org/).
83
+
84
+ Given a version number MAJOR.MINOR.PATCH, increment the:
85
+
86
+ - MAJOR version when you make incompatible API changes
87
+ - MINOR version when you add functionality in a backward compatible manner
88
+ - PATCH version when you make backward compatible bug fixes
89
+
90
+ Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the Pubmedly project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/robsimpsondev/pubmedly/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module Pubmedly
6
+ # The Client class provides methods for accessing the NCBI's eutils Pubmed API that
7
+ # return HTTP objects.
8
+ #
9
+ # The NCBI eutils API provides access to many databases, but these out of the scope of pubmedly:
10
+ # https://www.ncbi.nlm.nih.gov/books/NBK25497/table/chapter2.T._entrez_unique_identifiers_ui/?report=objectonly
11
+ class Client
12
+ BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/"
13
+ NCBI_DB = "pubmed"
14
+
15
+ def initialize(api_key)
16
+ @api_key = api_key
17
+ end
18
+
19
+ # https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch
20
+ # For guidance on search terms: https://pubmed.ncbi.nlm.nih.gov/help/#how-do-i-search-pubmed
21
+ # To understand term mapping: https://pubmed.ncbi.nlm.nih.gov/help/#automatic-term-mapping
22
+ # List of all field tags: https://pubmed.ncbi.nlm.nih.gov/help/#search-tags
23
+ # Parameters for retrieval: https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch
24
+ # datetype parameter options: https://dataguide.nlm.nih.gov/eutilities/utilities.html#esearch-date-filter-parameters
25
+ def search(term, **kwargs)
26
+ url = URI.parse("#{BASE_URL}esearch.fcgi")
27
+
28
+ params = kwargs.merge({
29
+ db: NCBI_DB,
30
+ api_key: @api_key,
31
+ term: term,
32
+ })
33
+
34
+ url.query = URI.encode_www_form(params)
35
+
36
+ http = Net::HTTP.new(url.host, url.port)
37
+ http.use_ssl = true
38
+
39
+ http.request(Net::HTTP::Get.new(url.request_uri))
40
+ end
41
+
42
+ # https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EFetch
43
+ def fetch(*ids, **kwargs)
44
+ url = URI.parse("#{BASE_URL}efetch.fcgi")
45
+
46
+ params = kwargs.merge(
47
+ db: NCBI_DB,
48
+ api_key: @api_key,
49
+ id: ids.join(",")
50
+ )
51
+
52
+ url.query = URI.encode_www_form(params)
53
+
54
+ http = Net::HTTP.new(url.host, url.port)
55
+ http.use_ssl = true
56
+
57
+ http.request(Net::HTTP::Get.new(url.request_uri))
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+ require "date"
5
+
6
+ module Pubmedly
7
+ module Parsers
8
+ # The Article class provides methods to access Article data.
9
+ class Article
10
+ attr_reader :xml
11
+
12
+ def initialize(xml)
13
+ @xml = xml
14
+ end
15
+
16
+ def to_s
17
+ "#{authors.first.split(",").first} (#{publication_date.year}) #{title}"
18
+ end
19
+
20
+ def title
21
+ @xml.xpath(".//ArticleTitle").text
22
+ end
23
+
24
+ def publication_date
25
+ date_str = @xml.xpath(".//PubDate").text
26
+ begin
27
+ date_str.empty? ? "" : Date.parse(date_str)
28
+ rescue Date::Error
29
+ Date.strptime(date_str.strip, "%Y")
30
+ end
31
+ end
32
+
33
+ def abstract
34
+ @xml.xpath(".//Abstract").text
35
+ end
36
+
37
+ def authors
38
+ @xml.xpath(".//Author").map do |author|
39
+ "#{author.xpath(".//LastName").text}, #{author.xpath(".//ForeName").text}"
40
+ end
41
+ end
42
+
43
+ def pmid
44
+ id = @xml.xpath(".//PMID").text.to_i
45
+ id.zero? ? nil : id
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+
5
+ module Pubmedly
6
+ module Parsers
7
+ # The Response class parses XML from the NCBI eutils API's responses.
8
+ class Response
9
+ def initialize(response)
10
+ @xml = Nokogiri::XML(response.body)
11
+ end
12
+
13
+ def count
14
+ @xml.xpath(".//Count")&.text.to_i
15
+ end
16
+
17
+ def ids
18
+ @xml.xpath(".//Id")&.map(&:text)&.map(&:to_i)&.to_a
19
+ end
20
+
21
+ def articles
22
+ @xml.xpath(".//PubmedArticle").map do |article_xml|
23
+ Pubmedly::Parsers::Article.new(article_xml)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubmedly
4
+ # The Pubmed class is the main entry point for the gem. It is initialized
5
+ # with an NCBI API key and exposes methods for searching and fetching
6
+ # articles.
7
+ #
8
+ # @example
9
+ # pubmed = Pubmedly::Pubmed.new("my_api_key")
10
+ # pubmed.search("cancer") # returns an array of Pubmed IDs
11
+ # pubmed.fetch(37194105) # returns an array of Articles
12
+ # pubmed.articles("cancer") # returns an array of Articles
13
+ #
14
+ class Pubmed
15
+ def initialize(api_key)
16
+ @client = Client.new(api_key)
17
+ end
18
+
19
+ def search(...)
20
+ Parsers::Response.new(@client.search(...)).ids
21
+ end
22
+
23
+ def fetch(...)
24
+ Parsers::Response.new(@client.fetch(...)).articles
25
+ end
26
+
27
+ def articles(term, **kwargs)
28
+ fetch(search(term, **kwargs), **kwargs)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pubmedly
4
+ VERSION = "0.2.0"
5
+ end
data/lib/pubmedly.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pubmedly/version"
4
+ require_relative "pubmedly/client"
5
+ require_relative "pubmedly/parsers/article"
6
+ require_relative "pubmedly/parsers/response"
7
+ require_relative "pubmedly/pubmed"
8
+
9
+ module Pubmedly
10
+ class ApiWarning < StandardError; end
11
+ # Your code goes here...
12
+ end
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pubmedly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Simpson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: os
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-reload
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Search the NIH database for medical research.
182
+ email:
183
+ - robsimpsondev@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".rspec"
189
+ - ".rubocop.yml"
190
+ - CHANGELOG.md
191
+ - CODE_OF_CONDUCT.md
192
+ - Gemfile
193
+ - Gemfile.lock
194
+ - LICENSE.txt
195
+ - README.md
196
+ - Rakefile
197
+ - lib/pubmedly.rb
198
+ - lib/pubmedly/client.rb
199
+ - lib/pubmedly/parsers/article.rb
200
+ - lib/pubmedly/parsers/response.rb
201
+ - lib/pubmedly/pubmed.rb
202
+ - lib/pubmedly/version.rb
203
+ homepage: https://github.com/robsimpsondev/pubmedly
204
+ licenses:
205
+ - MIT
206
+ metadata:
207
+ rubygems_mfa_required: 'true'
208
+ homepage_uri: https://github.com/robsimpsondev/pubmedly
209
+ source_code_uri: https://github.com/robsimpsondev/pubmedly
210
+ changelog_uri: https://github.com/robsimpsondev/pubmedly/CHANGELOG.md
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: 3.0.0
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubygems_version: 3.4.10
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Ruby client for the NCBI eutils Pubmed API
230
+ test_files: []