Module: AsciidocBib::FileHandlers
- Defined in:
- lib/asciidoc-bib/filehandlers.rb
Overview
Utility methods for working with the files.
Class Method Summary collapse
-
.add_ref(filename) ⇒ Object
Add '-ref' before the extension of a given filename, returning full path of new filename.
-
.find_bibliography(dir) ⇒ Object
Locate a bibliography file (*.bib) to read in given directory.
Class Method Details
.add_ref(filename) ⇒ Object
Add '-ref' before the extension of a given filename, returning full path of new filename.
25 26 27 28 29 30 |
# File 'lib/asciidoc-bib/filehandlers.rb', line 25 def FileHandlers.add_ref filename file_dir = File.dirname(File.(filename)) file_base = File.basename(filename, ".*") file_ext = File.extname(filename) return "#{file_dir}#{File::SEPARATOR}#{file_base}-ref#{file_ext}" end |
.find_bibliography(dir) ⇒ Object
Locate a bibliography file (*.bib) to read in given directory. Returns "" if any error or no file found.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/asciidoc-bib/filehandlers.rb', line 10 def FileHandlers.find_bibliography dir begin candidates = Dir.glob("#{dir}/*.bib") if candidates.empty? return "" else return candidates.first end rescue # catch all errors, and return empty string return "" end end |