arx 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 292c64f4c39d1d5a1d20ea803f98bd2f02f9830af51babcb1d8a2048ca06b403
4
- data.tar.gz: 75ad806933191bcbb3d84c6aad20bcc73f18c559c0c122ca57d49e23f3f7757a
3
+ metadata.gz: b2fa216412d2bdf6261f3fd1ada0b0c50498f13e5a8142dfd3db3433b693e4b4
4
+ data.tar.gz: 31c272fcc9d1ed4750e88d4c179035a0f37995f1afc030378e656f402a2dfeec
5
5
  SHA512:
6
- metadata.gz: 6b77f4ada7df3953695822feef7ca7e1f0feeb3d2a5375e3a37b9ae3a6db2d5c03db7979f19a19b6483e74226ca91113324052778a86a12b3f426e5689098b6a
7
- data.tar.gz: 419f468c377406c8459528c8755330986b8c3c0545788a9efb99f0f1ee9902a9fc618f4dc760b7b083c9988180f8877cf7cc03ed1e0be8d725552105d7e72044
6
+ metadata.gz: 8b8c8abf18d875a40e098f95dfb7452389a3b44691ecae568028563b12e5aa02e8b0233bf7fdfc25df58594df30b43f4caca37cf57df43240006ff22a5cfcdec
7
+ data.tar.gz: a8a40c0d3ccd18a86945e69a136b2275dcfd88a2ddc3678ab3b555f576e68b1d50d346b1c1a233def7bff62cb60fa0a071a870fcd6c41f34dcb8cf217d422437
@@ -1,3 +1,22 @@
1
+ # 0.3.2
2
+
3
+ #### Major changes
4
+
5
+ - Add `Paper#category` alias for `Paper#primary_category`. ([#34](https://github.com/eonu/arx/pull/34))
6
+ - Change `Author#affiliations?` to `Author#affiliated?`. ([#34](https://github.com/eonu/arx/pull/34))
7
+ - Change `Paper#last_updated` to `Paper#updated_at` (and remove `updated_at` alias). ([#34](https://github.com/eonu/arx/pull/34))
8
+ - Change `Paper#publish_date` to `Paper#published_at` (and remove `published_at` alias). ([#34](https://github.com/eonu/arx/pull/34))
9
+ - Conditionally assign query object in `Arx.search` with `||=` operator. ([#33](https://github.com/eonu/arx/pull/33))
10
+ - Add `gem:debug` rake task for loading the gem into an interactive console. ([#28](https://github.com/eonu/arx/pull/28))
11
+ - Add `gem:release` rake task for preparing gem releases. ([#36](https://github.com/eonu/arx/pull/36))
12
+ - Add `thor` gem development dependency. ([#36](https://github.com/eonu/arx/pull/36))
13
+
14
+ #### Minor changes
15
+
16
+ - Update documentation links to `rubydoc.info`'s GitHub service. ([#30](https://github.com/eonu/arx/pull/30))
17
+ - Add email address to `LICENSE`. ([#31](https://github.com/eonu/arx/pull/31))
18
+ - Improve `Error::MissingField` and `Error::MissingLink` error messages. ([#35](https://github.com/eonu/arx/pull/35))
19
+
1
20
  # 0.3.1
2
21
 
3
22
  #### Major changes
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Edwin Onuonga
3
+ Copyright (c) 2019 Edwin Onuonga <ed@mail.eonu.net>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![License](https://img.shields.io/github/license/eonu/arx.svg)](https://github.com/eonu/arx/blob/master/LICENSE)
8
8
 
9
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/e94073dfa8c3e2442298/maintainability)](https://codeclimate.com/github/eonu/arx/maintainability)
10
- [![Documentation](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/gems/arx/toplevel)
10
+ [![Documentation](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/github/eonu/arx/master/toplevel)
11
11
  [![Build Status](https://travis-ci.com/eonu/arx.svg?branch=master)](https://travis-ci.com/eonu/arx)
12
12
 
13
13
  **A Ruby interface for querying academic papers on the arXiv search API.**
@@ -41,7 +41,7 @@ $ gem install arx
41
41
 
42
42
  ## Documentation
43
43
 
44
- The documentation for Arx is hosted on [![rubydoc.info](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/gems/arx/toplevel).
44
+ The documentation for Arx is hosted on [![rubydoc.info](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/github/eonu/arx/master/toplevel).
45
45
 
46
46
  ## Usage
47
47
 
@@ -287,13 +287,13 @@ paper.revision?
287
287
  paper.comment?
288
288
  #=> false
289
289
  paper.comment
290
- #=> Arx::Error::MissingField (This arXiv paper is missing the `comment` field)
290
+ #=> Arx::Error::MissingField (arXiv paper 1809.09415v1 is missing the `comment` metadata field)
291
291
 
292
292
  # Paper's journal reference
293
293
  paper.journal?
294
294
  #=> false
295
295
  paper.journal
296
- #=> Arx::Error::MissingField (This arXiv paper is missing the `journal` field)
296
+ #=> Arx::Error::MissingField (arXiv paper 1809.09415v1 is missing the `journal` metadata field)
297
297
 
298
298
  # Paper's PDF URL
299
299
  paper.pdf?
@@ -320,7 +320,7 @@ author = paper.authors.first
320
320
  author.name
321
321
  #=> "F. Gebhard"
322
322
 
323
- author.affiliations?
323
+ author.affiliated?
324
324
  #=> true
325
325
  author.affiliations
326
326
  #=> ["ILL Grenoble, France"]
data/Rakefile CHANGED
@@ -1,7 +1,65 @@
1
+ require 'thor'
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new :spec
3
5
 
4
6
  desc 'Run application specs'
5
- RSpec::Core::RakeTask.new :spec
7
+ task default: [:spec]
8
+
9
+ namespace :gem do
10
+ class T < Thor
11
+ include Thor::Actions
12
+ end
13
+
14
+ desc 'Debug the gem (load into IRB)'
15
+ task :debug do
16
+ exec 'bundle exec rake install && irb -I lib/arx.rb -r arx'
17
+ end
18
+
19
+ desc 'Prepare a new gem release'
20
+ task :release, %i[major minor patch meta] do |task, args|
21
+ array = args.to_a
22
+ raise ArgumentError.new("Expected at least 3 SemVer segments, got #{array.size}") if array.size < 3
23
+ raise ArgumentError.new("Expected no more than 4 SemVer segments, got #{array.size}") if array.size > 4
24
+ args.to_h.each_with_index do |(segment, value), index|
25
+ next if index == array.size - 1 && array.size == 4
26
+ raise TypeError.new("Invalid #{segment} SemVer segment: #{value}") unless value == value.to_i.to_s
27
+ end
28
+
29
+ versions = args.to_h.transform_values {|v| v.to_i if Integer(v) rescue v}
30
+ versions[:meta] ||= nil
31
+ update_version versions
32
+
33
+ version = versions.compact.values.join('.')
34
+ add_changelog_entry version
35
+ end
36
+
37
+ private
38
+
39
+ def update_version(versions)
40
+ versions.each do |segment, value|
41
+ thor :gsub_file, File.join(__dir__, 'lib', 'arx', 'version.rb'), /#{segment}: .*,/, "#{segment}: #{value.inspect},"
42
+ end
43
+ end
44
+
45
+ def add_changelog_entry(version)
46
+ thor :insert_into_file, File.join(__dir__, 'CHANGELOG.md'), after: /\A/ do
47
+ <<-ENTRY
48
+ # #{version}
49
+
50
+ #### Major changes
51
+
52
+ - TODO
53
+
54
+ #### Minor changes
55
+
56
+ - TODO
57
+
58
+ ENTRY
59
+ end
60
+ end
6
61
 
7
- task default: [:spec]
62
+ def thor(*args, &block)
63
+ T.new.send *args, &block
64
+ end
65
+ end
@@ -23,12 +23,13 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 2.0'
25
25
  spec.add_development_dependency 'rake', '~> 12.3'
26
+ spec.add_development_dependency 'thor', '~> 0.20'
26
27
  spec.add_development_dependency 'rspec', '~> 3.7'
27
28
 
28
29
  spec.metadata = {
29
30
  'source_code_uri' => spec.homepage,
30
31
  'homepage_uri' => spec.homepage,
31
- 'documentation_uri' => 'https://www.rubydoc.info/gems/arx/toplevel',
32
+ 'documentation_uri' => 'https://www.rubydoc.info/github/eonu/arx/master/toplevel',
32
33
  'bug_tracker_uri' => "#{spec.homepage}/issues",
33
34
  'changelog_uri' => "#{spec.homepage}/blob/master/CHANGELOG.md"
34
35
  }
data/lib/arx.rb CHANGED
@@ -53,15 +53,12 @@ module Arx
53
53
  # @param sort_order [Symbol] The sorting order for the returned results (see {Query::SORT_ORDER}).
54
54
  # @return [Array<Paper>, Paper] The {Paper}(s) found by the search query.
55
55
  def search(*ids, query: nil, sort_by: :relevance, sort_order: :descending)
56
- if query.nil?
57
- query = Query.new(*ids, sort_by: sort_by, sort_order: sort_order)
58
- yield query if block_given?
59
- else
60
- raise TypeError.new("Expected `query` to be an Arx::Query, got: #{query.class}") unless query.is_a? Query
61
- end
56
+ query ||= Query.new(*ids, sort_by: sort_by, sort_order: sort_order)
57
+ raise TypeError.new("Expected `query` to be an Arx::Query, got: #{query.class}") unless query.is_a? Query
62
58
 
63
- document = Nokogiri::XML(open ENDPOINT + query.to_s + '&max_results=10000').remove_namespaces!
59
+ yield query if block_given?
64
60
 
61
+ document = Nokogiri::XML(open ENDPOINT + query.to_s + '&max_results=10000').remove_namespaces!
65
62
  results = Paper.parse(document, single: false).reject {|paper| paper.id.empty?}
66
63
  raise Error::MissingPaper.new(ids.first) if results.empty? && ids.size == 1
67
64
  ids.size == 1 && results.size == 1 ? results.first : results
@@ -17,13 +17,12 @@ module Arx
17
17
  # @return [Array<String>]
18
18
  has_many :affiliations, Cleaner, tag: 'affiliation', parser: :clean
19
19
 
20
- # @!method affiliations?
21
20
  # Whether or not the author has any affiliations.
22
21
  # @return [Boolean]
23
- def affiliations?
22
+ def affiliated?
24
23
  !affiliations.empty?
25
24
  end
26
25
 
27
- inspector :name, :affiliations?, :affiliations
26
+ inspector :name, :affiliated?, :affiliations
28
27
  end
29
28
  end
@@ -27,17 +27,15 @@ module Arx
27
27
  @id
28
28
  end
29
29
 
30
- # @!method last_updated
30
+ # @!method updated_at
31
31
  # The date that the paper was last updated.
32
32
  # @return [DateTime]
33
- element :last_updated, DateTime, tag: 'updated'
34
- alias_method :updated_at, :last_updated
33
+ element :updated_at, DateTime, tag: 'updated'
35
34
 
36
- # @!method publish_date
35
+ # @!method published_at
37
36
  # The original publish/submission date of the paper.
38
37
  # @return [DateTime]
39
- element :publish_date, DateTime, tag: 'published'
40
- alias_method :published_at, :publish_date
38
+ element :published_at, DateTime, tag: 'published'
41
39
 
42
40
  # @!method title
43
41
  # The title of the paper.
@@ -53,19 +51,18 @@ module Arx
53
51
  # The primary category of the paper.
54
52
  # @return [Category]
55
53
  element :primary_category, Category, tag: 'primary_category'
56
- alias_method :primary_subject, :primary_category
54
+ alias_method :category, :primary_category
57
55
 
58
56
  # @!method categories
59
57
  # The categories of the paper.
60
58
  # @return [Array<Category>]
61
59
  has_many :categories, Category, tag: 'category'
62
- alias_method :subjects, :categories
63
60
 
64
61
  # Whether the paper is a revision or not.
65
- # @note A paper is a revision if {last_updated} differs from {publish_date}.
62
+ # @note A paper is a revision if {updated_at} differs from {published_at}.
66
63
  # @return [Boolean]
67
64
  def revision?
68
- @publish_date != @last_updated
65
+ @published_at != @updated_at
69
66
  end
70
67
 
71
68
  # @!method summary
@@ -107,7 +104,7 @@ module Arx
107
104
  if self.send "#{optional}?"
108
105
  instance_variable_get("@#{optional}")
109
106
  else
110
- raise Error::MissingField.new(optional)
107
+ raise Error::MissingField.new id, optional
111
108
  end
112
109
  end
113
110
  end
@@ -149,7 +146,7 @@ module Arx
149
146
  if self.send exists
150
147
  links.find(&exists).href
151
148
  else
152
- raise Error::MissingLink.new link_type.to_s.upcase
149
+ raise Error::MissingLink.new id, link_type.to_s.upcase
153
150
  end
154
151
  end
155
152
  end
@@ -157,7 +154,7 @@ module Arx
157
154
  inspector *%i[
158
155
  id url title summary authors
159
156
  primary_category categories
160
- publish_date last_updated revision?
157
+ published_at updated_at revision?
161
158
  comment? comment
162
159
  journal? journal
163
160
  pdf? pdf_url
@@ -5,15 +5,15 @@ module Arx
5
5
 
6
6
  # Custom error for missing links on an arXiv paper.
7
7
  class MissingLink < StandardError
8
- def initialize(link_type)
9
- super "This arXiv paper does not have a #{link_type} link"
8
+ def initialize(id, link_type)
9
+ super "arXiv paper #{id} does not have a #{link_type} link"
10
10
  end
11
11
  end
12
12
 
13
13
  # Custom error for missing fields on an arXiv paper.
14
14
  class MissingField < StandardError
15
- def initialize(field)
16
- super "This arXiv paper is missing the `#{field}` field"
15
+ def initialize(id, field)
16
+ super "arXiv paper #{id} is missing the `#{field}` metadata field"
17
17
  end
18
18
  end
19
19
 
@@ -6,7 +6,7 @@ module Arx
6
6
  VERSION = {
7
7
  major: 0,
8
8
  minor: 3,
9
- patch: 1,
10
- meta: nil
9
+ patch: 2,
10
+ meta: nil,
11
11
  }.compact.values.join('.').freeze
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Onuonga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-27 00:00:00.000000000 Z
11
+ date: 2019-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '12.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.20'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.20'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +125,7 @@ licenses:
111
125
  metadata:
112
126
  source_code_uri: https://github.com/eonu/arx
113
127
  homepage_uri: https://github.com/eonu/arx
114
- documentation_uri: https://www.rubydoc.info/gems/arx/toplevel
128
+ documentation_uri: https://www.rubydoc.info/github/eonu/arx/master/toplevel
115
129
  bug_tracker_uri: https://github.com/eonu/arx/issues
116
130
  changelog_uri: https://github.com/eonu/arx/blob/master/CHANGELOG.md
117
131
  post_install_message: