Module: PdfExtract::ResolvedReferences

Defined in:
lib/references/resolved_references.rb

Class Method Summary collapse

Class Method Details

.include_in(pdf) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/references/resolved_references.rb', line 6

def self.include_in pdf
  pdf.spatials :resolved_references, :depends_on => [:references] do |parser|

    resolved_refs = []
    
    parser.objects :references do |ref|
      resolved_refs << ref.merge(Resolve.find(ref))
    end

    parser.after do
      resolved_refs
    end

  end
end

.reverse_resolve(ref) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/references/resolved_references.rb', line 22

def self.reverse_resolve ref
  
  url = "http://api.labs.crossref.org/search?q=#{CGI.escape(ref)}"
  doc = Nokogiri::HTML(open url)

  result = doc.at_css "div.result"
  score = result.at_css("span.cr_score").content.to_s
  if score.to_i >= 90
    result.at_css("span.doi").content.sub("http://dx.doi.org/", "")
  else
    ""
  end
end