Module: Metanorma::Collection::Util
- Defined in:
- lib/metanorma/collection/util/util.rb,
lib/metanorma/collection/util/disambig_files.rb
Defined Under Namespace
Classes: DisambigFiles, Dummy
Class Method Summary
collapse
Class Method Details
.add_suffix_to_attributes(doc, suffix, tag_name, attr_name, isodoc) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/metanorma/collection/util/util.rb', line 33
def add_suffix_to_attributes(doc, suffix, tag_name, attr_name,
isodoc)
(suffix.nil? || suffix.empty?) and return
doc.xpath(isodoc.ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
a = elem.attributes[attr_name].value
/_#{suffix}$/.match?(a) or
elem.attributes[attr_name].value = "#{a}_#{suffix}"
end
end
|
.gather_bibitemids(xml) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/metanorma/collection/util/util.rb', line 17
def 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
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/metanorma/collection/util/util.rb', line 5
def gather_bibitems(xml)
xml.xpath("//xmlns:bibitem[@id]").each_with_object({}) do |b, m|
if m[b["id"]]
b.remove
next
else
m[b["id"]] = b
end
end
end
|
.gather_citeases(xml) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/metanorma/collection/util/util.rb', line 25
def 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
|
.hash_key_detect(directives, key, variable) ⇒ Object
43
44
45
46
47
|
# File 'lib/metanorma/collection/util/util.rb', line 43
def hash_key_detect(directives, key, variable)
c = directives.detect { |x| x.key == key } or
return variable
c.value
end
|
.key(ident) ⇒ Object
56
57
58
59
|
# File 'lib/metanorma/collection/util/util.rb', line 56
def key(ident)
@c ||= HTMLEntities.new
@c.decode(ident).gsub(/(\p{Zs})+/, " ")
end
|
.load_isodoc(doctype) ⇒ Object
65
66
67
68
|
# File 'lib/metanorma/collection/util/util.rb', line 65
def load_isodoc(doctype)
x = Asciidoctor.load nil, backend: doctype.to_sym
x.converter.html_converter(Dummy.new) end
|
.rel_path_resolve(dir, path) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/metanorma/collection/util/util.rb', line 49
def rel_path_resolve(dir, path)
path.nil? and return path
path.empty? and return path
p = Pathname.new(path)
p.absolute? ? path : File.join(dir, path)
end
|