Class: Crossref::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/crossref.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/crossref.rb', line 9

def url
  @url
end

#xmlObject

Returns the value of attribute xml.



9
10
11
# File 'lib/crossref.rb', line 9

def xml
  @xml
end

Instance Method Details

#authorsObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/crossref.rb', line 43

def authors
  #first_author = self.xml.xpath('//person_name[@sequence="first"]').first
  #authors = [hashify_name(first_author.children)]
  #first_author.unlink

  authors = []
  self.xml.xpath('//contributors/person_name[@contributor_role="author"]').each do |a| 
   authors << hashify_nodes(a.children) 
  end
  authors
end

#journalObject



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

#publishedObject



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

#resourceObject



74
75
76
# File 'lib/crossref.rb', line 74

def resource
  xpath_first('//doi_data/resource')
end

#result?Boolean

Returns:

  • (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

#titleObject



38
39
40
# File 'lib/crossref.rb', line 38

def title
  xpath_first('//titles/title')
end