Class: Crossref::Metadata
- Inherits:
-
Object
- Object
- Crossref::Metadata
- Defined in:
- lib/crossref.rb
Instance Attribute Summary collapse
-
#doi(doi) ⇒ Object
Returns the value of attribute doi.
-
#url ⇒ Object
Returns the value of attribute url.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #authors ⇒ Object
-
#initialize(opts = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #journal ⇒ Object
- #published ⇒ Object
- #resource ⇒ Object
- #result? ⇒ Boolean
- #title ⇒ Object
- #xpath_first(q) ⇒ Object
- #xpath_ns(q, ns = 'http://www.crossref.org/xschema/1.0') ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Metadata
Returns a new instance of Metadata.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/crossref.rb', line 11 def initialize(opts = {}) @base_url = opts[:base_url] || 'http://crossref.org/openurl/?noredirect=true&format=unixref' @doi = opts[:doi] @pid = opts[:pid] @base_url += '&pid=' + @pid if @pid if @doi @doi = sanitize_doi(@doi) @url = @base_url + "&id=doi:" + @doi @xml = get_xml(@url) end end |
Instance Attribute Details
#doi(doi) ⇒ Object
Returns the value of attribute doi.
9 10 11 |
# File 'lib/crossref.rb', line 9 def doi @doi end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/crossref.rb', line 9 def url @url end |
#xml ⇒ Object
Returns the value of attribute xml.
9 10 11 |
# File 'lib/crossref.rb', line 9 def xml @xml end |
Instance Method Details
#authors ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/crossref.rb', line 44 def = [] xpath_ns('contributors/person_name[@contributor_role="author"]').each do |a| << hashify_nodes(a.children) end end |
#journal ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/crossref.rb', line 61 def journal journal = hashify_nodes(xpath_ns('journal_metadata').first.children) journal[:volume] = xpath_first('journal_issue/journal_volume/volume') journal[:issue] = xpath_first('journal_issue/issue') journal[:first_page] = xpath_first('first_page') journal[:last_page] = xpath_first('last_page') journal end |
#published ⇒ Object
53 54 55 56 57 58 |
# File 'lib/crossref.rb', line 53 def published pub = Hash.new pub[:year] = xpath_first('publication_date/year') pub[:month] = xpath_first('publication_date/month') pub end |
#resource ⇒ Object
71 72 73 |
# File 'lib/crossref.rb', line 71 def resource xpath_first('doi_data/resource') end |
#result? ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'lib/crossref.rb', line 30 def result? if self.xml.nil? || xpath_ns('error').size == 1 false else xpath_ns('doi_record').size == 1 end end |
#title ⇒ Object
39 40 41 |
# File 'lib/crossref.rb', line 39 def title xpath_first('titles/title') end |
#xpath_first(q) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/crossref.rb', line 79 def xpath_first(q) if info = xpath_ns(q).first info.content else nil end end |
#xpath_ns(q, ns = 'http://www.crossref.org/xschema/1.0') ⇒ Object
75 76 77 |
# File 'lib/crossref.rb', line 75 def xpath_ns(q, ns = 'http://www.crossref.org/xschema/1.0') self.xml.xpath("//#{q.split('/').map {|e| "xmlns:#{e}"}.join('/')}", 'xmlns' => ns) end |