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
Constructor Details
#initialize(opts = {}) ⇒ Metadata
Returns a new instance of Metadata.
11 12 13 14 15 16 17 18 19 20 21 |
# 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 @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
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/crossref.rb', line 43 def #first_author = self.xml.xpath('//person_name[@sequence="first"]').first #authors = [hashify_name(first_author.children)] #first_author.unlink = [] self.xml.xpath('//contributors/person_name[@contributor_role="author"]').each do |a| << hashify_nodes(a.children) end end |
#journal ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/crossref.rb', line 64 def journal journal = hashify_nodes(self.xml.xpath('//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
56 57 58 59 60 61 |
# File 'lib/crossref.rb', line 56 def published pub = Hash.new pub[:year] = self.xml.xpath('//publication_date/year') pub[:month] = self.xml.xpath('//publication_date/month') pub end |
#resource ⇒ Object
74 75 76 |
# File 'lib/crossref.rb', line 74 def resource xpath_first('//doi_data/resource') end |
#result? ⇒ Boolean
29 30 31 32 33 34 35 |
# File 'lib/crossref.rb', line 29 def result? if self.xml.nil? || self.xml.xpath('//error').size == 1 false else self.xml.xpath('//doi_record').size == 1 end end |
#title ⇒ Object
38 39 40 |
# File 'lib/crossref.rb', line 38 def title xpath_first('//titles/title') end |