ref2bibtex 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c153ef1ea1467b62160f9e8459db3a108d88a3dd
4
- data.tar.gz: 4a4f80870eb9512f4d2b747f809ea9a6cfdf4486
2
+ SHA256:
3
+ metadata.gz: ca0c289e6130dd3be2e0f7a550a7d05c3f492c9cf1fe0d3ec66e64ec04d2dba2
4
+ data.tar.gz: 2f2f5e9d4c1b79092a72a27851b64a6cf4e608d44c9f4ac6acfac30d5afdaaaa
5
5
  SHA512:
6
- metadata.gz: c2316279add7c7bbd4b77c43786d7b5c9dc1ada8b0f7d57be9a936b51859512c02958907baf5214f802aeae713450d332c5e0b751367c71f4dfecb5607669d59
7
- data.tar.gz: c73aacc42c22c4d7c87d1e4450325dffffb31912800551d5aba3cc522f77b440cb73e41c3061acd753e10581d616a4d39708062a2711c5ae241291f9d1791540
6
+ metadata.gz: 1fea65fa7e3b3931440512a5df8c6f4c01ea8ae2537868c97a6e83a6118f4efe9a5f0f0eb615db08080cbb3fc1e4f67368725c1c31db84c9bc053914660f49fe
7
+ data.tar.gz: 3923cc54cfbf6c0cff0c1c2d1fe5d170af15dad1de7b47d4000aaf04c3352dcfd94d4ecc2f136de991f47b0cfcbcfb7c27e976877fec51c0b0aab98002b75d5d
@@ -1,8 +1,10 @@
1
1
  ---
2
2
  rvm:
3
- - 2.3.3
3
+ - 2.5.1
4
4
  branches:
5
5
  only:
6
6
  - master
7
7
  install:
8
8
  - bundle install
9
+ cache:
10
+ bundler: true
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ref2bibtex (0.2.3)
5
- addressable (~> 2.5)
4
+ ref2bibtex (0.3.0)
5
+ addressable (~> 2.6)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.5.2)
10
+ addressable (2.6.0)
11
11
  public_suffix (>= 2.0.2, < 4.0)
12
12
  awesome_print (1.8.0)
13
- byebug (9.1.0)
13
+ byebug (11.0.0)
14
14
  diff-lcs (1.3)
15
15
  public_suffix (3.0.3)
16
16
  rake (12.3.2)
@@ -33,11 +33,11 @@ PLATFORMS
33
33
 
34
34
  DEPENDENCIES
35
35
  awesome_print (~> 1.8.0)
36
- bundler (~> 1.16)
37
- byebug (~> 9.1)
36
+ bundler (~> 2.0)
37
+ byebug (~> 11)
38
38
  rake (~> 12.3)
39
39
  ref2bibtex!
40
- rspec
40
+ rspec (~> 3.8)
41
41
 
42
42
  BUNDLED WITH
43
- 1.17.1
43
+ 2.0.1
@@ -1,11 +1,13 @@
1
- recent_ruby = RUBY_VERSION >= '2.1.0'
2
- raise "IMPORTANT: gem requires ruby >= 2.1.0" unless recent_ruby
1
+ recent_ruby = RUBY_VERSION >= '2.3.0'
2
+ raise "IMPORTANT: gem requires ruby >= 2.3.0" unless recent_ruby
3
3
 
4
4
  require "ref2bibtex/version"
5
5
  require 'json'
6
6
  require 'net/http'
7
7
  require 'cgi'
8
- require "addressable/uri"
8
+ require 'addressable/uri'
9
+
10
+ # require 'serrano'
9
11
 
10
12
  module Ref2bibtex
11
13
 
@@ -48,33 +50,46 @@ module Ref2bibtex
48
50
  end
49
51
  end
50
52
 
51
- # Pass a String doi get a bibtex formatted string back
52
- #
53
+ # @params doi [String]
54
+ # @return [String, false]
53
55
  def self.get_bibtex(doi)
54
56
  return false if !doi
57
+
55
58
  doi = Addressable::URI.parse(doi).normalize.to_s
56
59
  uri = URI(doi)
57
60
  return false if uri.class == URI::Generic
58
- response = Ref2bibtex.request(uri, headers: {'Accept' => 'application/x-bibtex' }, protocol: 'GET', process_response_as: 'text')
61
+
62
+ # Serrano.content_negotiation(ids: doi).first
63
+
64
+ Ref2bibtex.request(uri, headers: {'Accept' => 'application/x-bibtex' }, protocol: 'GET', process_response_as: 'text')
59
65
  end
60
-
66
+
67
+ # @param citation [String]
68
+ # @return [String, false]
61
69
  # Pass a String citation, get a DOI back
62
70
  def self.get_doi(citation)
63
71
  citation = validate_query(citation)
64
72
  response = Ref2bibtex.request(payload: citation)
65
-
66
- return false if !response['results'][0]['match']
73
+ return false unless has_match?(response)
67
74
  return false if response['results'][0]['score'] < @@cutoff
68
-
69
75
  response['results'][0]['doi']
70
76
  end
71
77
 
78
+ # @param citation [String]
79
+ # @return [Float, -1.0
72
80
  # Pass a String citation, get a score back
73
81
  def self.get_score(citation)
74
82
  citation = validate_query(citation)
75
83
  response = Ref2bibtex.request(payload: citation)
76
- return false if !response['results'][0]['match']
77
- response['results'][0]['score']
84
+ if has_match?(response)
85
+ response['results'].first['score']
86
+ else
87
+ -1.0
88
+ end
89
+ end
90
+
91
+ def self.has_match?(response)
92
+ response['query_ok'] && response['results']&.first['match']
78
93
  end
79
94
 
80
95
  def self.validate_query(citation)
@@ -116,10 +131,11 @@ module Ref2bibtex
116
131
  http.request(request)
117
132
  end
118
133
  else
134
+
119
135
  response = response.value
120
136
  end
121
137
 
122
- process_response(response, process_response_as)
138
+ process_response(response, process_response_as)
123
139
  end
124
140
 
125
141
  protected
@@ -1,3 +1,3 @@
1
1
  module Ref2bibtex
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -18,12 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "addressable", "~> 2.5"
21
+ spec.add_dependency "addressable", "~> 2.6"
22
+ # spec.add_dependency "serrano"
22
23
 
23
- spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "bundler", "~> 2.0"
24
25
  spec.add_development_dependency "rake", "~> 12.3"
25
- spec.add_development_dependency "byebug", "~> 9.1"
26
+ spec.add_development_dependency "byebug", "~> 11"
26
27
  spec.add_development_dependency "awesome_print", "~> 1.8.0"
27
- spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec", "~> 3.8"
28
29
 
29
30
  end
@@ -28,7 +28,7 @@ describe Ref2bibtex do
28
28
 
29
29
  context '.get_doi' do
30
30
  specify 'takes a full citation and returns a string' do
31
- expect(Ref2bibtex.get_doi(CITATIONS[:first])).to eq('http://dx.doi.org/10.3897/zookeys.20.205')
31
+ expect(Ref2bibtex.get_doi(CITATIONS[:first])).to eq('https://doi.org/10.3897/zookeys.20.205')
32
32
  end
33
33
 
34
34
  specify 'a citation that can not be resolved returns false' do
@@ -41,7 +41,7 @@ describe Ref2bibtex do
41
41
  end
42
42
 
43
43
  context '.get_bibtex' do
44
- let(:response) { Ref2bibtex.get_bibtex('http://dx.doi.org/10.3897/zookeys.20.205')}
44
+ let(:response) { Ref2bibtex.get_bibtex('https://dx.doi.org/10.3897/zookeys.20.205')}
45
45
  specify 'takes a full citation and returns bibtex' do
46
46
  expect(response).to match(/author\s=/)
47
47
  expect(response).to match(/title\s=/)
@@ -71,10 +71,12 @@ describe Ref2bibtex do
71
71
  context 'interpretation' do
72
72
  before(:all) {
73
73
  @scores = CITATIONS.keys.inject({}) { |hsh, c|
74
+ sleep 0.5 # throttle timing a little
74
75
  hsh.merge!(
75
76
  c => Ref2bibtex.get_score(CITATIONS[c])
76
77
  )
77
78
  }
79
+ @scores
78
80
  }
79
81
 
80
82
  specify 'mangled text is worse than good text' do
@@ -82,7 +84,7 @@ describe Ref2bibtex do
82
84
  end
83
85
 
84
86
  context 'default @@cutoff is reasonable and slightly conservative' do
85
- let(:good_citations) { [:first, :second, :third, :fourth, :sixth] }
87
+ let(:good_citations) { [:first, :second, :third] } # remainders have moved to unresolvable
86
88
  let(:bad_citations) { CITATIONS.keys - good_citations }
87
89
 
88
90
  specify 'for good citations' do
@@ -94,6 +96,7 @@ describe Ref2bibtex do
94
96
  specify 'for bad citations' do
95
97
  bad_citations.each do |c|
96
98
  if @scores[c]
99
+
97
100
  expect(@scores[c]).to be < Ref2bibtex.cutoff
98
101
  end
99
102
  end
@@ -111,7 +114,8 @@ describe Ref2bibtex do
111
114
  expect(Ref2bibtex.get_doi(CITATIONS[:first])).to eq(false)
112
115
  end
113
116
 
114
- specify 'can be used to accept bad matches' do
117
+ # Cutoff is more finely tuned to exclude bad matches now.
118
+ xspecify 'can be used to accept bad matches' do
115
119
  Ref2bibtex.cutoff = 1
116
120
  expect(Ref2bibtex.get_doi(CITATIONS[:fifth])).to be_truthy
117
121
  end
@@ -10,7 +10,7 @@
10
10
  :fifth:
11
11
  "Iam, F.K. 1337. Let's go Crossref, give me a DOI for this fake reference in my unit test, I dare you. Journal of Examples for Unit tests. 13:37"
12
12
  :sixth:
13
- "Simon, E. (1879b) Les Arachnides de France. Tome 7. Contenant les ordres des Chernetes, Scorpiones et Opiliones. Librairie Encyclopédique de Roret, Paris, pp. 1–332, pl. 17–24. "
13
+ "Simon, E. (1879b) Les Arachnides de France. Tome 7. Contenant les ordres des Chernetes, Scorpiones et Opiliones. Librairie Encyclopédique de Roret, Paris, pp. 1–332, pl. 17–24."
14
14
  :seventh:
15
15
  'Jaost & K.P. Shuw. 2007. Phyloguny of Ensifere (Hesapoda: Prthoptera) usine threa rubosomal toci, wuth implocations far teh evolushun off acoustik commmunication. Tolecular Fylogenetics & Evolotion (Mul. Phylagenet. Evil.) 39:509-528'
16
16
  :eighth:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ref2bibtex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Yoder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.5'
19
+ version: '2.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.5'
26
+ version: '2.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '9.1'
61
+ version: '11'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '9.1'
68
+ version: '11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: awesome_print
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '3.8'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '3.8'
97
97
  description: Ok, maybe a bit more, you can pass a DOI and get the bibtex string back
98
98
  too.
99
99
  email:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.6.14.1
139
+ rubygems_version: 2.7.8
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Pass a full citation, get the bibtex back, that's all.