Module: Metanorma::Util
- Defined in:
- lib/metanorma/util.rb
Defined Under Namespace
Classes: DisambigFiles
Class Method Summary collapse
- .gather_bibitemids(xml) ⇒ Object
- .gather_bibitems(xml) ⇒ Object
- .gather_citeases(xml) ⇒ Object
- .log(message, type = :info) ⇒ Object
- .recursive_string_keys(hash) ⇒ Object
- .sort_extensions_execution(ext) ⇒ Object
-
.sort_extensions_execution_ord(ext) ⇒ Object
dependency ordering.
Class Method Details
.gather_bibitemids(xml) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/metanorma/util.rb', line 47 def self.gather_bibitemids(xml) xml.xpath("//*[@bibitemid]").each_with_object({}) do |e, m| /^semantic__/.match?(e.name) and next m[e["bibitemid"]] ||= [] m[e["bibitemid"]] << e end end |
.gather_bibitems(xml) ⇒ Object
41 42 43 44 45 |
# File 'lib/metanorma/util.rb', line 41 def self.gather_bibitems(xml) xml.xpath("//xmlns:bibitem[@id]").each_with_object({}) do |b, m| m[b["id"]] = b end end |
.gather_citeases(xml) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/metanorma/util.rb', line 55 def self.gather_citeases(xml) xml.xpath("//*[@citeas]").each_with_object({}) do |e, m| /^semantic__/.match?(e.name) and next m[e["citeas"]] ||= [] m[e["citeas"]] << e end end |
.log(message, type = :info) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/metanorma/util.rb', line 3 def self.log(, type = :info) log_types = Metanorma.configuration.logs.map(&:to_s) || [] if log_types.include?(type.to_s) puts() end if type == :fatal exit(1) end end |
.recursive_string_keys(hash) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/metanorma/util.rb', line 32 def self.recursive_string_keys(hash) case hash when Hash then hash.map { |k, v| [k.to_s, recursive_string_keys(v)] }.to_h when Enumerable then hash.map { |v| recursive_string_keys(v) } else hash end end |
.sort_extensions_execution(ext) ⇒ Object
26 27 28 29 30 |
# File 'lib/metanorma/util.rb', line 26 def self.sort_extensions_execution(ext) ext.sort do |a, b| sort_extensions_execution_ord(a) <=> sort_extensions_execution_ord(b) end end |
.sort_extensions_execution_ord(ext) ⇒ Object
dependency ordering
16 17 18 19 20 21 22 23 24 |
# File 'lib/metanorma/util.rb', line 16 def self.sort_extensions_execution_ord(ext) case ext when :xml then 0 when :rxl then 1 when :presentation then 2 else 99 end end |