Class: IsoDoc::JIS::Xref

Inherits:
Iso::Xref
  • Object
show all
Defined in:
lib/isodoc/jis/xref.rb

Instance Method Summary collapse

Instance Method Details

#annex_name_lbl(clause, num) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/isodoc/jis/xref.rb', line 20

def annex_name_lbl(clause, num)
  obl = l10n("(#{@labels['inform_annex']})")
  clause["obligation"] == "normative" and
    obl = l10n("(#{@labels['norm_annex']})")
  title = Common::case_with_markup(@labels["annex"], "capital", @script)
  l10n("#{title} #{num}<br/>#{obl}")
end

#back_clauses_anchor_names(xml) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/isodoc/jis/xref.rb', line 59

def back_clauses_anchor_names(xml)
  clause_order_back(xml).each do |a|
    xml.xpath(ns(a[:path])).each do |c|
      if c["commentary"] == "true" then commentary_names(c)
      else preface_names(c)
      end
      x = Nokogiri::XML::NodeSet.new(c.document, [c])
      sequential_asset_names(x, container: true)
      a[:multi] or break
    end
  end
end

#clause_order_annex(_docxml) ⇒ Object



41
42
43
# File 'lib/isodoc/jis/xref.rb', line 41

def clause_order_annex(_docxml)
  [{ path: "//annex[not(@commentary = 'true')]", multi: true }]
end

#clause_order_back(_docxml) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/isodoc/jis/xref.rb', line 45

def clause_order_back(_docxml)
  [
    { path: @klass.bibliography_xpath },
    { path: "//annex[@commentary = 'true']", multi: true },
    { path: "//indexsect", multi: true },
    { path: "//colophon/*", multi: true },
  ]
end

#clause_order_main(docxml) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/isodoc/jis/xref.rb', line 28

def clause_order_main(docxml)
  [
    { path: "//sections/introduction" },
    { path: "//clause[@type = 'scope']" },
    { path: @klass.norm_ref_xpath },
    { path: "//sections/terms | " \
            "//sections/clause[descendant::terms]" },
    { path: "//sections/definitions | " \
            "//sections/clause[descendant::definitions][not(descendant::terms)]" },
    { path: @klass.middle_clause(docxml), multi: true },
  ]
end

#commentary_name_anchors(clause, num, root, level) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/isodoc/jis/xref.rb', line 88

def commentary_name_anchors(clause, num, root, level)
  @anchors[clause["id"]] =
    { label: num, xref: l10n("#{@labels['clause']} #{num}"),
      container: root,
      title: clause_title(clause), level: level, type: "clause",
      elem: @labels["clause"] }
end

#commentary_names(clause) ⇒ Object



72
73
74
75
76
77
# File 'lib/isodoc/jis/xref.rb', line 72

def commentary_names(clause)
  preface_name_anchors(clause, 1, clause_title(clause))
  clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
    commentary_names1(c, clause["id"], i.increment(c).print, 2)
  end
end

#commentary_names1(clause, root, num, level) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/isodoc/jis/xref.rb', line 79

def commentary_names1(clause, root, num, level)
  commentary_name_anchors(clause, num, root, level)
  clause.xpath(ns(SUBCLAUSES))
    .each_with_object(Counter.new(0, prefix: "#{num}.")) do |c, i|
    commentary_names1(c, root, i.increment(c).print,
                      level + 1)
  end
end

#list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/isodoc/jis/xref.rb', line 96

def list_item_anchor_names(list, list_anchor, depth, prev_label,
refer_list)
  c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
  list.xpath(ns("./li")).each do |li|
    bare_label, label = list_item_value(li, c, depth,
                                        { list_anchor: list_anchor, prev_label: prev_label, refer_list: refer_list })
    li["id"] and @anchors[li["id"]] =
                   { label: bare_label, bare_xref: "#{bare_label})",
                     xref: "#{label})", type: "listitem", refer_list:
                                  refer_list, container: list_anchor[:container] }
    (li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
      list_item_anchor_names(ol, list_anchor, depth + 1, label, false)
    end
  end
end

#list_item_value(entry, counter, depth, opts) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/isodoc/jis/xref.rb', line 112

def list_item_value(entry, counter, depth, opts)
  label1 = counter.increment(entry).listlabel(entry.parent, depth)
  if depth > 2
    base = opts[:prev_label].match(/^(.*?)([0-9.]+)$/) # a) 1.1.1
    label1 = "#{base[2]}.#{label1}"
    [label1, list_item_anchor_label(label1, opts[:list_anchor],
                                    base[1].sub(/[^a-z0-9]*$/, ""), opts[:refer_list])]
  else
    [label1, list_item_anchor_label(label1, opts[:list_anchor], opts[:prev_label],
                                    opts[:refer_list])]
  end
end

#section_names(clause, num, lvl) ⇒ Object



54
55
56
57
# File 'lib/isodoc/jis/xref.rb', line 54

def section_names(clause, num, lvl)
  clause&.name == "introduction" and clause["unnumbered"] = "true"
  super
end