crossref 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-05-06
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/crossref
6
+ lib/crossref.rb
7
+ test/test_crossref.rb
data/README.txt ADDED
@@ -0,0 +1,5 @@
1
+ = crossref
2
+
3
+ * http://github.com/ottbot/crossref/tree
4
+
5
+ See README.rdoc
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/crossref.rb'
6
+
7
+ Hoe.new('crossref', Crossref::VERSION) do |p|
8
+ # p.rubyforge_name = 'crossrefx' # if different than lowercase project name
9
+ p.developer('Robert Crim', 'robert@servermilk.com')
10
+ p.remote_rdoc_dir = ''
11
+ end
12
+
13
+ # vim: syntax=Ruby
data/bin/crossref ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ abort "you need to write me"
data/lib/crossref.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module Crossref
6
+ VERSION = '0.0.1'
7
+
8
+ class Metadata
9
+ attr_accessor :doi, :url, :xml
10
+
11
+ def initialize(opts = {})
12
+ @base_url = opts[:base_url] || 'http://crossref.org/openurl/?noredirect=true&format=unixref'
13
+ @doi = opts[:doi]
14
+ @pid = opts[:pid]
15
+ @base_url += '&pid=' + @pid if @pid
16
+
17
+ if @doi
18
+ @url = @base_url + "&id=doi:" + @doi
19
+ @xml = get_xml(@url)
20
+ end
21
+ end
22
+
23
+
24
+ def doi(doi)
25
+ Crossref::Metadata.new(:doi => doi, :pid => @pid, :url => @base_url)
26
+ end
27
+
28
+
29
+ def result?
30
+ if self.xml.nil? || self.xml.xpath('//error').size == 1
31
+ false
32
+ else
33
+ self.xml.xpath('//doi_record').size == 1
34
+ end
35
+ end
36
+
37
+
38
+ def title
39
+ xpath_first('//titles/title')
40
+ end
41
+
42
+
43
+ def authors
44
+ #first_author = self.xml.xpath('//person_name[@sequence="first"]').first
45
+ #authors = [hashify_name(first_author.children)]
46
+ #first_author.unlink
47
+
48
+ authors = []
49
+ self.xml.xpath('//contributors/person_name[@contributor_role="author"]').each do |a|
50
+ authors << hashify_nodes(a.children)
51
+ end
52
+ authors
53
+ end
54
+
55
+
56
+ def published
57
+ pub = Hash.new
58
+ pub[:year] = self.xml.xpath('//publication_date/year')
59
+ pub[:month] = self.xml.xpath('//publication_date/month')
60
+ pub
61
+ end
62
+
63
+
64
+ def journal
65
+ journal = hashify_nodes(self.xml.xpath('//journal_metadata').first.children)
66
+ journal[:volume] = xpath_first('//journal_issue/journal_volume/volume')
67
+ journal[:issue] = xpath_first('//journal_issue/issue')
68
+ journal[:first_page] = xpath_first('//first_page')
69
+ journal[:last_page] = xpath_first('//last_page')
70
+
71
+ journal
72
+ end
73
+
74
+ def resource
75
+ xpath_first('//doi_data/resource')
76
+ end
77
+
78
+ #------------------------------------------------------
79
+ private
80
+
81
+ def xpath_first(q)
82
+ self.xml.xpath(q).first.content
83
+ end
84
+
85
+ def get_xml(url)
86
+ Nokogiri::XML(open(url))
87
+ end
88
+
89
+ def hashify_nodes(nodes)
90
+ h = {}
91
+ nodes.each do |node|
92
+ h[node.name.to_sym] = node.content unless node.content.match(/\n/)
93
+ end
94
+ h
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "crossref"
3
+
4
+ class TestCrossref < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crossref
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Crim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-08 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.12.2
24
+ version:
25
+ description: ""
26
+ email:
27
+ - robert@servermilk.com
28
+ executables:
29
+ - crossref
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - bin/crossref
42
+ - lib/crossref.rb
43
+ - test/test_crossref.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/ottbot/crossref/tree
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --main
51
+ - README.txt
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: crossref
69
+ rubygems_version: 1.3.3
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: ""
73
+ test_files:
74
+ - test/test_crossref.rb