Module: Metanorma::Standoc::Amend
- Included in:
- Cleanup
- Defined in:
- lib/metanorma/cleanup/amend.rb
Instance Method Summary collapse
- #change_clauses(docxml) ⇒ Object
- #create_amend(clause) ⇒ Object
- #create_amend1(clause, amend) ⇒ Object
-
#create_amend2(clause, amend) ⇒ Object
possible formats: DESC? BLOCKQUOTE DESC?; DESC? BLOCKQUOTE? SUBCLAUSES+.
- #create_amend2_prep(_clause, amend) ⇒ Object
- #create_amend_autonum(amend) ⇒ Object
- #move_attrs_to_amend(clause, amend) ⇒ Object
- #move_attrs_to_amend_locality(_clause, amend) ⇒ Object
Instance Method Details
#change_clauses(docxml) ⇒ Object
4 5 6 7 8 |
# File 'lib/metanorma/cleanup/amend.rb', line 4 def change_clauses(docxml) docxml.xpath("//clause[@change]").each do |c| create_amend(c) end end |
#create_amend(clause) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/cleanup/amend.rb', line 10 def create_amend(clause) a = clause.add_child("<amend/>").first add_id(a) clause.elements.each do |e| e.parent = a unless %w(amend title).include? e.name end create_amend1(clause, a) end |
#create_amend1(clause, amend) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/metanorma/cleanup/amend.rb', line 19 def create_amend1(clause, amend) create_amend2(clause, amend) move_attrs_to_amend(clause, amend) create_amend_autonum(amend) amend end |
#create_amend2(clause, amend) ⇒ Object
possible formats: DESC? BLOCKQUOTE DESC?; DESC? BLOCKQUOTE? SUBCLAUSES+
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metanorma/cleanup/amend.rb', line 38 def create_amend2(clause, amend) q, pre, post = create_amend2_prep(clause, amend) if q.empty? amend.children = "<description>#{amend.children.to_xml}</description>" return end ins = amend.add_child("<newcontent/>").first q.each { |n| ins << n.remove } pre.empty? or ins.previous = "<description>#{pre.to_xml}</description>" post.empty? or ins.next = "<description>#{post.to_xml}</description>" end |
#create_amend2_prep(_clause, amend) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/metanorma/cleanup/amend.rb', line 50 def create_amend2_prep(_clause, amend) ret = amend.xpath("./quote[1]") ret += amend.xpath("./clause") ret.empty? and return [[], nil, nil] pre = ret[0].xpath("./preceding-sibling::*").each(&:remove) post = ret[-1].xpath("./following-sibling::*").each(&:remove) ret[0].name == "quote" and ret = ret[0].remove.children + ret[1..] [ret, pre, post] end |
#create_amend_autonum(amend) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/metanorma/cleanup/amend.rb', line 26 def create_amend_autonum(amend) autonum = (amend.xpath(".//autonumber") - amend.xpath(".//clause//autonumber")).map(&:remove) amend.xpath(".//p[normalize-space(.)='']").each(&:remove) ins = amend.children.first autonum.each { |a| ins.previous = a } (amend.xpath(".//clause") - amend.xpath(".//clause/clause")).each do |c| create_amend_autonum(c) end end |
#move_attrs_to_amend(clause, amend) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/metanorma/cleanup/amend.rb', line 60 def move_attrs_to_amend(clause, amend) %w(change path path_end title position).each do |e| clause[e] or next amend[e] = clause[e] clause.delete(e) end move_attrs_to_amend_locality(clause, amend) end |
#move_attrs_to_amend_locality(_clause, amend) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/metanorma/cleanup/amend.rb', line 69 def move_attrs_to_amend_locality(_clause, amend) amend["locality"] or return loc = amend.children.add_previous_sibling("<location/>") extract_localities1(loc, amend["locality"]) loc1 = loc.at("./localityStack") and loc.replace(loc1.elements) amend.delete("locality") end |