Class: BibSync::Actions::FindMyCitations
- Inherits:
-
Object
- Object
- BibSync::Actions::FindMyCitations
- Defined in:
- lib/bibsync/actions/find_my_citations.rb
Constant Summary
Constants included from Log
Log::Blue, Log::Level, Log::Red, Log::Reset, Log::Yellow
Instance Method Summary collapse
-
#initialize(options) ⇒ FindMyCitations
constructor
A new instance of FindMyCitations.
- #run ⇒ Object
Methods included from Utils
#arxiv_download, #arxiv_id, #fetch, #fetch_xml, #name_without_ext
Methods included from Log
Constructor Details
#initialize(options) ⇒ FindMyCitations
Returns a new instance of FindMyCitations.
7 8 9 10 11 |
# File 'lib/bibsync/actions/find_my_citations.rb', line 7 def initialize() raise 'Option --bib is required' unless @bib = [:bib] raise 'Option --citedbyme is required' unless @dir = [:citedbyme] raise "#{@dir} is not a directory" unless File.directory?(@dir) end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/bibsync/actions/find_my_citations.rb', line 13 def run notice 'Find citations in my TeX files' cites = {} Dir[File.join(@dir, '**/*.tex')].each do |file| File.read(file).scan(/cite\{([^\}]+)\}/) do $1.split(/\s*,\s*/).each do |key| key.strip! file = @bib.relative_path(file) debug("Cited in #{file}", key: key) (cites[key] ||= []) << file end end end @bib.each do |entry| next if entry.comment? entry.delete(:cites) unless cites.include?(entry.key) end cites.each do |key, files| files = files.sort.uniq.join(';') if @bib[key] @bib[key][:citedbyme] = files else warning("Cited in #{files} but not found in #{@bib.file}", key: key) end end end |