crossref 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/crossref.rb +26 -21
  2. metadata +4 -4
@@ -3,7 +3,7 @@ require 'nokogiri'
3
3
  require 'open-uri'
4
4
 
5
5
  module Crossref
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.4'
7
7
 
8
8
  class Metadata
9
9
  attr_accessor :doi, :url, :xml
@@ -28,26 +28,22 @@ module Crossref
28
28
 
29
29
 
30
30
  def result?
31
- if self.xml.nil? || self.xml.xpath('//error').size == 1
31
+ if self.xml.nil? || xpath_ns('error').size == 1
32
32
  false
33
33
  else
34
- self.xml.xpath('//doi_record').size == 1
34
+ xpath_ns('doi_record').size == 1
35
35
  end
36
36
  end
37
37
 
38
38
 
39
39
  def title
40
- xpath_first('//titles/title')
40
+ xpath_first('titles/title')
41
41
  end
42
42
 
43
43
 
44
44
  def authors
45
- #first_author = self.xml.xpath('//person_name[@sequence="first"]').first
46
- #authors = [hashify_name(first_author.children)]
47
- #first_author.unlink
48
-
49
45
  authors = []
50
- self.xml.xpath('//contributors/person_name[@contributor_role="author"]').each do |a|
46
+ xpath_ns('contributors/person_name[@contributor_role="author"]').each do |a|
51
47
  authors << hashify_nodes(a.children)
52
48
  end
53
49
  authors
@@ -56,33 +52,42 @@ module Crossref
56
52
 
57
53
  def published
58
54
  pub = Hash.new
59
- pub[:year] = xpath_first('//publication_date/year')
60
- pub[:month] = xpath_first('//publication_date/month')
55
+ pub[:year] = xpath_first('publication_date/year')
56
+ pub[:month] = xpath_first('publication_date/month')
61
57
  pub
62
58
  end
63
59
 
64
60
 
65
61
  def journal
66
- journal = hashify_nodes(self.xml.xpath('//journal_metadata').first.children)
67
- journal[:volume] = xpath_first('//journal_issue/journal_volume/volume')
68
- journal[:issue] = xpath_first('//journal_issue/issue')
69
- journal[:first_page] = xpath_first('//first_page')
70
- journal[:last_page] = xpath_first('//last_page')
62
+ journal = hashify_nodes(xpath_ns('journal_metadata').first.children)
63
+ journal[:volume] = xpath_first('journal_issue/journal_volume/volume')
64
+ journal[:issue] = xpath_first('journal_issue/issue')
65
+ journal[:first_page] = xpath_first('first_page')
66
+ journal[:last_page] = xpath_first('last_page')
71
67
 
72
68
  journal
73
69
  end
74
70
 
75
71
  def resource
76
- xpath_first('//doi_data/resource')
72
+ xpath_first('doi_data/resource')
77
73
  end
78
-
79
- #------------------------------------------------------
80
- private
81
74
 
75
+ def xpath_ns(q, ns = 'http://www.crossref.org/xschema/1.0')
76
+ self.xml.xpath("//#{q.split('/').map {|e| "xmlns:#{e}"}.join('/')}", 'xmlns' => ns)
77
+ end
78
+
82
79
  def xpath_first(q)
83
- self.xml.xpath(q).first.content
80
+ if info = xpath_ns(q).first
81
+ info.content
82
+ else
83
+ nil
84
+ end
84
85
  end
85
86
 
87
+ #------------------------------------------------------
88
+ private
89
+
90
+
86
91
  def get_xml(url)
87
92
  Nokogiri::XML(open(url))
88
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crossref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Crim
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-11 00:00:00 +01:00
12
+ date: 2009-09-21 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.12.2
33
+ version: 2.3.3
34
34
  version:
35
35
  description: ""
36
36
  email:
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements: []
77
77
 
78
78
  rubyforge_project: crossref
79
- rubygems_version: 1.3.3
79
+ rubygems_version: 1.3.5
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: ""