Class: BibSync::Actions::Validate

Inherits:
Object
  • Object
show all
Includes:
Log, Utils
Defined in:
lib/bibsync/actions/validate.rb

Constant Summary

Constants included from Log

Log::Blue, Log::Level, Log::Red, Log::Reset, Log::Yellow

Instance Method Summary collapse

Methods included from Log

#log

Methods included from Utils

#arxiv_download, #arxiv_id, #fetch, #fetch_xml, #name_without_ext

Constructor Details

#initialize(options) ⇒ Validate

Returns a new instance of Validate.



7
8
9
# File 'lib/bibsync/actions/validate.rb', line 7

def initialize(options)
  raise 'Option --bib is required' unless @bib = options[:bib]
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bibsync/actions/validate.rb', line 11

def run
  notice 'Check validity'
  titles, arxivs, dois = {}, {}, {}

  @bib.each do |entry|
    next if entry.comment?

    w = []

    file = entry.file

    missing = []
    missing << :file unless file && File.file?(file[:path])
    missing += [:title, :author, :year, :abstract].reject {|k| entry[k] }
    w << "Missing #{missing.map(&:to_s).sort.join(', ')}" unless missing.empty?

    w << 'File name does not match entry key' if name_without_ext(file[:name]) != entry.key if file

    if entry[:arxiv]
      id = arxiv_id(entry, version: false, prefix: true)
      if arxivs.include?(id)
        w << "ArXiv duplicate of '#{arxivs[id]}'"
      else
        arxivs[id] = entry.key
      end
    end

    if id = entry[:doi]
      if dois.include?(id)
        w << "DOI duplicate of '#{dois[id]}'"
      else
        dois[id] = entry.key
      end
    end

    if entry[:title]
      if titles.include?(entry[:title])
        w << "Title duplicate of '#{titles[entry[:title]]}'"
      else
        titles[entry[:title]] = entry.key
      end
    end

    warning(w.join('; '), key: entry) unless w.empty?
  end
end