doi2bibtex 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 205f080615db64f7f2e41114d6fb99e0c064699b
4
+ data.tar.gz: c981f74fb45a10eb69defabf687fdfdcb52e96c7
5
+ SHA512:
6
+ metadata.gz: 8f3531609469a8f84f1fd82a3ee1a112dd2500bf7c2ef1feb781d52d5ebc6fd1bee3ef3ec5a645228ce968b3b791ecd0eb0991305b9a2a57790aa7e844142127
7
+ data.tar.gz: a617d5563fa11c0787ba9e8e7404fce2c71e5360cf4024903b127d72d9292d1b3f04d86764bd0ee53e0a456e943f9a88da3845e5f81c1db2f571d60c1e1deae8
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ branches:
5
+ only:
6
+ - master
7
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.3.1'
4
+
5
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ doi2bibtex (0.1.0)
5
+ thor (~> 0.19)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.0)
11
+ public_suffix (~> 2.0, >= 2.0.2)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ hashdiff (0.3.2)
15
+ minitest (5.10.1)
16
+ minitest-rg (5.2.0)
17
+ minitest (~> 5.0)
18
+ public_suffix (2.0.5)
19
+ rake (11.3.0)
20
+ safe_yaml (1.0.4)
21
+ thor (0.19.4)
22
+ vcr (3.0.3)
23
+ webmock (2.3.2)
24
+ addressable (>= 2.3.6)
25
+ crack (>= 0.3.2)
26
+ hashdiff
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ doi2bibtex!
33
+ minitest (~> 5.9)
34
+ minitest-rg (~> 5.2)
35
+ rake (~> 11.3)
36
+ vcr (~> 3.0)
37
+ webmock (~> 2.1)
38
+
39
+ RUBY VERSION
40
+ ruby 2.3.1p112
41
+
42
+ BUNDLED WITH
43
+ 1.13.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Kiwi-Learn
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Doi2bibtex
2
+ [![Build Status](https://travis-ci.org/vicky-sunshine/doi2bibtex.svg?branch=master)](https://travis-ci.org/vicky-sunshine/doi2bibtex)
3
+ <!-- [![Gem Version](https://badge.fury.io/rb/weatherscout.svg)](https://badge.fury.io/rb/weatherscout) -->
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => [:spec]
4
+
5
+ desc 'Run specs'
6
+ Rake::TestTask.new(name=:spec) do |t|
7
+ t.pattern = 'spec/*_spec.rb'
8
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'doi2bibtex' # for production
4
+
5
+ class Doi2bibtexCLI < Thor
6
+ desc 'get DOI', 'see the bibtex of the paper'
7
+ def get(doi)
8
+ bib = Doi2bibtex::Doi2bibtex.new(doi)
9
+ puts "#{bib.bibtex}"
10
+ end
11
+ end
12
+
13
+ Doi2bibtexCLI.start(ARGV)
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'doi2bibtex/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'doi2bibtex'
5
+ s.version = Doi2bibtex::VERSION
6
+ s.date = Doi2bibtex::DATE
7
+ s.executables << 'doi2bibtex'
8
+ s.summary = 'Convert DOI to BibTeX'
9
+ s.description = 'Give DOI of a paper and get corresponding BibTeX'
10
+ s.authors = ['Chi-Hsuan Li']
11
+ s.email = ['lch82327@gmail.com']
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files spec/*`.split("\n")
14
+ s.homepage = 'https://github.com/vicky-sunshine/doi2bibtex'
15
+ s.license = 'MIT'
16
+
17
+ # depend gem
18
+ s.add_runtime_dependency 'thor', '~> 0.19'
19
+ s.add_development_dependency 'minitest', '~> 5.9'
20
+ s.add_development_dependency 'minitest-rg', '~> 5.2'
21
+ s.add_development_dependency 'rake', '~> 11.3'
22
+ s.add_development_dependency 'vcr', '~> 3.0'
23
+ s.add_development_dependency 'webmock', '~> 2.1'
24
+
25
+ s.homepage = 'https://github.com/vicky-sunshine/doi2bibtex'
26
+ s.license = 'MIT'
27
+ end
@@ -0,0 +1 @@
1
+ require 'doi2bibtex/doi2bibtex.rb'
@@ -0,0 +1,121 @@
1
+ require 'uri'
2
+ require "cgi"
3
+
4
+ module Doi2bibtex
5
+ # parse daily weather description from cwb website
6
+ class Doi2bibtex
7
+ attr_reader :doi, :bibtex
8
+ private :hash
9
+
10
+ CROSSREF_URL = 'http://data.crossref.org/'.freeze
11
+
12
+ def initialize(doi)
13
+ @doi ||= doi
14
+ handle_doi_request
15
+ parsing_bibtex
16
+ end
17
+
18
+ def url
19
+ CGI.unescape(@hash["url"])
20
+ end
21
+
22
+ def author
23
+ @hash["author"].to_s
24
+ end
25
+
26
+ def title
27
+ @hash["title"].to_s
28
+ end
29
+
30
+ def journal?
31
+ !@hash["journal"].nil?
32
+ end
33
+
34
+ def book_title
35
+ if journal?
36
+ @hash["journal"].to_s
37
+ else
38
+ @hash["booktitle"].to_s
39
+ end
40
+ end
41
+
42
+ def publisher
43
+ @hash["publisher"].to_s
44
+ end
45
+
46
+ def volume
47
+ @hash["volume"].nil? ? nil:@hash["volume"].to_i
48
+ end
49
+
50
+ def issue
51
+ @hash["number"].nil? ? nil:@hash["number"].to_i
52
+ end
53
+
54
+ def pages
55
+ @hash["pages"].to_s.gsub('--', '-')
56
+ end
57
+
58
+ def year
59
+ @hash["year"].to_i
60
+ end
61
+
62
+ def month
63
+ if @hash["month"].nil?
64
+ nil
65
+ else
66
+ Date::MONTHNAMES.index(@hash["month"].capitalize)
67
+ end
68
+ end
69
+
70
+ def inspect
71
+ "<#{Doi2bibtex}:0x#{'%x' % (object_id << 1)} @doi=#{doi.inspect}, @bibtex=#{@bibtex.inspect}>"
72
+ end
73
+
74
+ def to_s
75
+ bibtex
76
+ end
77
+
78
+ def to_h
79
+ {
80
+ doi: doi,
81
+ url: url,
82
+ author: author,
83
+ title: title,
84
+ book_title: book_title,
85
+ publisher: publisher,
86
+ volume: volume,
87
+ issue: issue,
88
+ pages: pages,
89
+ year: year,
90
+ month: month
91
+ }
92
+ end
93
+
94
+ private
95
+
96
+ def handle_doi_request
97
+ url = URI(CROSSREF_URL + doi)
98
+
99
+ http = Net::HTTP.new(url.host, url.port)
100
+ request = Net::HTTP::Get.new(url)
101
+ request["accept"] = 'application/x-bibtex'
102
+ res = http.request(request)
103
+
104
+ # res = HTTP.headers(:accept => 'application/x-bibtex').get(CROSSREF_URL + doi)
105
+ if res.code.to_i == 200
106
+ @bibtex ||= res.body
107
+ else
108
+ @bibtex = nil
109
+ end
110
+ end
111
+
112
+ def parsing_bibtex
113
+ if bibtex.nil?
114
+ @hash = nil
115
+ else
116
+ data = bibtex.delete("{},\\").delete("\n").split("\t").drop(1)
117
+ @hash ||= data.map { |e| e.split(" = ")}.to_h
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ # Versioning
2
+ module Doi2bibtex
3
+ VERSION = '0.1.0'
4
+ DATE = '2017-02-16'
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'vcr'
2
+ require 'webmock'
3
+ require 'minitest/autorun'
4
+ require 'minitest/rg'
5
+
6
+ require_relative '../lib/doi2bibtex.rb'
7
+
8
+ DOI = "10.1109/JPROC.2014.2371999".freeze
9
+
10
+ VCR.configure do |config|
11
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
12
+ config.hook_into :webmock
13
+ end
14
+
15
+ VCR.use_cassette('doi2bibtex') do
16
+ bib = Doi2bibtex::Doi2bibtex.new(DOI)
17
+ describe 'test for doi' do
18
+ it 'should return doi' do
19
+ bib.doi.must_be_instance_of String
20
+ end
21
+ it 'should have doi format' do
22
+ bib.doi.must_match(/[0-9\.]+\/[a-zA-Z0-9\.]+/)
23
+ end
24
+ end
25
+
26
+ describe 'test for title' do
27
+ it 'should return title name' do
28
+ bib.title.must_be_instance_of String
29
+ end
30
+ end
31
+
32
+ describe 'test for url' do
33
+ it 'should have url' do
34
+ bib.url.must_be_instance_of String
35
+ end
36
+ it 'should have url format' do
37
+ bib.url.must_match(/https:\/\/doi.org\/[0-9\.]+\/[a-zA-Z0-9\.]+/)
38
+ end
39
+ end
40
+
41
+ describe 'test for author' do
42
+ it 'should have author' do
43
+ bib.author.must_be_instance_of String
44
+ end
45
+ end
46
+
47
+ describe 'test for book_title' do
48
+ it 'should have book_title' do
49
+ bib.book_title.must_be_instance_of String
50
+ end
51
+ end
52
+
53
+ describe 'test for year' do
54
+ it 'should have year' do
55
+ bib.year.must_be_instance_of Fixnum
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://data.crossref.org/10.1109/JPROC.2014.2371999
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/x-bibtex
12
+ Connection:
13
+ - close
14
+ Host:
15
+ - data.crossref.org
16
+ User-Agent:
17
+ - http.rb/2.2.1
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Access-Control-Allow-Origin:
24
+ - "*"
25
+ Access-Control-Allow-Headers:
26
+ - X-Requested-With, Accept, Accept-Encoding, Accept-Charset, Accept-Language,
27
+ Accept-Ranges, Cache-Control
28
+ Access-Control-Expose-Headers:
29
+ - Link
30
+ Link:
31
+ - <http://dx.doi.org/10.1109/jproc.2014.2371999>; rel="canonical"
32
+ Content-Type:
33
+ - application/x-bibtex
34
+ Content-Length:
35
+ - '524'
36
+ Server:
37
+ - http-kit
38
+ Date:
39
+ - Fri, 17 Feb 2017 16:43:28 GMT
40
+ Connection:
41
+ - close
42
+ body:
43
+ encoding: ASCII-8BIT
44
+ string: "@article{Kreutz_2015,\n\tdoi = {10.1109/jproc.2014.2371999},\n\turl
45
+ = {https://doi.org/10.1109%2Fjproc.2014.2371999},\n\tyear = 2015,\n\tmonth
46
+ = {jan},\n\tpublisher = {Institute of Electrical and Electronics Engineers
47
+ ({IEEE})},\n\tvolume = {103},\n\tnumber = {1},\n\tpages = {14--76},\n\tauthor
48
+ = {Diego Kreutz and Fernando M. V. Ramos and Paulo Esteves Verissimo and Christian
49
+ Esteve Rothenberg and Siamak Azodolmolky and Steve Uhlig},\n\ttitle = {Software-Defined
50
+ Networking: A Comprehensive Survey},\n\tjournal = {Proceedings of the {IEEE}}\n}"
51
+ http_version:
52
+ recorded_at: Fri, 17 Feb 2017 16:43:28 GMT
53
+ recorded_with: VCR 3.0.3
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doi2bibtex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chi-Hsuan Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-rg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ description: Give DOI of a paper and get corresponding BibTeX
98
+ email:
99
+ - lch82327@gmail.com
100
+ executables:
101
+ - doi2bibtex
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/doi2bibtex
113
+ - doi2bibtex.gemspec
114
+ - lib/doi2bibtex.rb
115
+ - lib/doi2bibtex/doi2bibtex.rb
116
+ - lib/doi2bibtex/version.rb
117
+ - spec/doi2bibtex_spec.rb
118
+ - spec/fixtures/vcr_cassettes/doi2bibtex.yml
119
+ homepage: https://github.com/vicky-sunshine/doi2bibtex
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Convert DOI to BibTeX
143
+ test_files:
144
+ - spec/doi2bibtex_spec.rb
145
+ - spec/fixtures/vcr_cassettes/doi2bibtex.yml