arxiv 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,9 @@ module Arxiv
20
20
  ID_FORMAT = /^\d{4}\.\d{4}(?:v\d+)?$/
21
21
 
22
22
  def self.get(id)
23
+
24
+ id = parse_arxiv_id(id)
25
+
23
26
  raise Arxiv::Error::MalformedId, "Manuscript ID format is invalid" unless id =~ ID_FORMAT
24
27
 
25
28
  url = ::URI.parse("http://export.arxiv.org/api/query?id_list=#{id}")
@@ -30,4 +33,17 @@ module Arxiv
30
33
  manuscript
31
34
  end
32
35
 
36
+ private
37
+
38
+ def self.parse_arxiv_id(id)
39
+ if id =~ ID_FORMAT
40
+ id
41
+ elsif id =~ /arxiv.org/
42
+ match = id.match(/[^\/]+$/)
43
+ match[0] if match
44
+ else
45
+ id
46
+ end
47
+ end
48
+
33
49
  end
@@ -1,3 +1,3 @@
1
1
  module Arxiv
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -13,15 +13,24 @@ module Arxiv
13
13
  it "should fetch a manuscript when passed a valid id" do
14
14
  Arxiv.get('1202.0819').should fetch_valid_manuscript
15
15
  end
16
+
16
17
  it "should fetch a manuscript when passed a valid id with a version number" do
17
18
  Arxiv.get('1202.0819v1').should fetch_valid_manuscript
18
19
  end
19
- it "should raise a manuscript not found error when the manuscript cannot be found on arXiv" do
20
- lambda { Arxiv.get('1234.1234') }.should raise_error(Arxiv::Error::ManuscriptNotFound)
20
+
21
+ it "should fetch a manuscript when passed full URL for a manuscript" do
22
+ Arxiv.get('http://arxiv.org/abs/1202.0819').should fetch_valid_manuscript
21
23
  end
22
- it "should raise a malformed id error when the manuscript id has an incorrect format" do
23
- lambda { Arxiv.get('cond-mat0709123') }.should raise_error(Arxiv::Error::MalformedId)
24
+
25
+ context "errors" do
26
+ it "should raise a manuscript not found error when the manuscript cannot be found on arXiv" do
27
+ lambda { Arxiv.get('1234.1234') }.should raise_error(Arxiv::Error::ManuscriptNotFound)
28
+ end
29
+ it "should raise a malformed id error when the manuscript id has an incorrect format" do
30
+ lambda { Arxiv.get('cond-mat0709123') }.should raise_error(Arxiv::Error::MalformedId)
31
+ end
24
32
  end
33
+
25
34
  end
26
35
 
27
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arxiv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-02-14 00:00:00.000000000Z
14
+ date: 2012-02-15 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: happymapper
18
- requirement: &2153141080 !ruby/object:Gem::Requirement
18
+ requirement: &2157600480 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2153141080
26
+ version_requirements: *2157600480
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
- requirement: &2153140660 !ruby/object:Gem::Requirement
29
+ requirement: &2157600060 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2153140660
37
+ version_requirements: *2157600060
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &2153140240 !ruby/object:Gem::Requirement
40
+ requirement: &2157599640 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *2153140240
48
+ version_requirements: *2157599640
49
49
  description: Makes interacting with arXiv data really easy.
50
50
  email:
51
51
  - coryschires@gmail.com