Class: Metanorma::Standoc::LocalBiblio
- Inherits:
-
Object
- Object
- Metanorma::Standoc::LocalBiblio
- Defined in:
- lib/metanorma/standoc/localbib.rb
Instance Method Summary collapse
- #file_error(config) ⇒ Object
- #format_error(config) ⇒ Object
- #get(id, file = default) ⇒ Object
- #init_file_bibdb1(defn, key) ⇒ Object
- #init_file_bibdb_config(defn, key) ⇒ Object
-
#initialize(node, localdir, parent) ⇒ LocalBiblio
constructor
A new instance of LocalBiblio.
- #read_file(config) ⇒ Object
- #read_files(node) ⇒ Object
Constructor Details
#initialize(node, localdir, parent) ⇒ LocalBiblio
Returns a new instance of LocalBiblio.
6 7 8 9 10 11 |
# File 'lib/metanorma/standoc/localbib.rb', line 6 def initialize(node, localdir, parent) @file_bibdb = {} @localdir = localdir @parent = parent read_files(node) end |
Instance Method Details
#file_error(config) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/metanorma/standoc/localbib.rb', line 50 def file_error(config) msg = "Cannot process file #{config['file']} for local relaton " \ "data source #{config['key']}" @parent.log.add("Bibliography", nil, msg, severity: 0) "" end |
#format_error(config) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/metanorma/standoc/localbib.rb', line 57 def format_error(config) msg = "Cannot process format #{config['format']} for local relaton " \ "data source #{config['key']}" @parent.log.add("Bibliography", nil, msg, severity: 0) {} end |
#get(id, file = default) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/standoc/localbib.rb', line 64 def get(id, file = default) ret = @file_bibdb.dig(file, id) and return ret msg = "Cannot find reference #{id} for local relaton " \ "data source #{file}" @parent.log.add("Bibliography", nil, msg, severity: 0) Nokogiri::XML("<bibitem/>") end |
#init_file_bibdb1(defn, key) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metanorma/standoc/localbib.rb', line 32 def init_file_bibdb1(defn, key) v = init_file_bibdb_config(defn, key) r = read_file(v) @file_bibdb[v["key"]] = case v["format"] when "bibtex" RelatonBib::BibtexParser.from_bibtex(r) else format_error(v) end end |
#init_file_bibdb_config(defn, key) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/metanorma/standoc/localbib.rb', line 24 def init_file_bibdb_config(defn, key) /=/.match?(defn) or defn = "file=#{defn}" values = defn.split(",").map { |item| item.split /(?<!\s)\s*=\s*/ }.to_h values["key"] = key values["format"] ||= "bibtex" # all we currently suppoort values end |
#read_file(config) ⇒ Object
44 45 46 47 48 |
# File 'lib/metanorma/standoc/localbib.rb', line 44 def read_file(config) f = File.join(@localdir, config["file"]) File.exist?(f) or return file_error(config) File.read(f) end |
#read_files(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/metanorma/standoc/localbib.rb', line 13 def read_files(node) if node.attr("relaton-data-source") init_file_bibdb1(node.attr("relaton-data-source"), "default") else node.attributes.each do |k, v| /^relaton-data-source-.+/.match?(k) or next init_file_bibdb1(v, k.sub(/^relaton-data-source-/, "")) end end end |