Class: IsoDoc::Jis::Xref

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#autonumbering_styleObject

Returns the value of attribute autonumbering_style.



28
29
30
# File 'lib/isodoc/jis/xref.rb', line 28

def autonumbering_style
  @autonumbering_style
end

Instance Method Details

#annex_name_anchors1(clause, num, level) ⇒ Object



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

def annex_name_anchors1(clause, num, level)
  super
  # undo ISO "Clause A.2" in favour of "A.2"
  level == 2 and
    @anchors[clause["id"]][:xref] =  semx(clause, num)
end

#annex_name_lbl(clause, num) ⇒ Object



78
79
80
# File 'lib/isodoc/jis/xref.rb', line 78

def annex_name_lbl(clause, num)
  super.gsub(%r{</?strong>}, "")
end

#back_clauses_anchor_names(xml) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/isodoc/jis/xref.rb', line 130

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_counter(num, opts = { }) ⇒ Object



34
35
36
37
38
# File 'lib/isodoc/jis/xref.rb', line 34

def clause_counter(num, opts = { })
  opts[:numerals] ||= @autonumbering_style
  opts[:separator] ||= clausesep
  super
end

#clause_order_annex(_docxml) ⇒ Object



102
103
104
# File 'lib/isodoc/jis/xref.rb', line 102

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

#clause_order_back(_docxml) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/isodoc/jis/xref.rb', line 106

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



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/jis/xref.rb', line 89

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

#clausesepObject



30
31
32
# File 'lib/isodoc/jis/xref.rb', line 30

def clausesep
  @autonumbering_style == :japanese ? "\u30fb" : "."
end

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



161
162
163
164
165
166
167
# File 'lib/isodoc/jis/xref.rb', line 161

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

#commentary_names(clause) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/isodoc/jis/xref.rb', line 143

def commentary_names(clause)
  preface_name_anchors(clause, 1, clause_title(clause))
  clause.xpath(ns(SUBCLAUSES))
    .each_with_object(clause_counter(0, {})) do |c, i|
      commentary_names1(c, clause["id"], nil, i.increment(c).print, 2)
    end
end

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



151
152
153
154
155
156
157
158
159
# File 'lib/isodoc/jis/xref.rb', line 151

def commentary_names1(clause, root, parentnum, num, level)
  lbl = clause_number_semx(parentnum, clause, num)
  commentary_name_anchors(clause, lbl, root, level)
  clause.xpath(ns(SUBCLAUSES))
    .each_with_object(clause_counter(0)) do |c, i|
      commentary_names1(c, root, lbl, i.increment(c).print,
                        level + 1)
    end
end

#hierfigsepObject



46
47
48
# File 'lib/isodoc/jis/xref.rb', line 46

def hierfigsep
  @lang == "ja" ? "の" : super
end

#hierreqtsepObject



50
51
52
# File 'lib/isodoc/jis/xref.rb', line 50

def hierreqtsep
  @lang == "ja" ? "の" : super
end

#list_counter(num, opts = { }) ⇒ Object



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

def list_counter(num, opts = { })
  opts[:numerals] ||= @autonumbering_style
  opts[:separator] ||= clausesep
  IsoDoc::Jis::Counter.new(num, opts)
end

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



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/isodoc/jis/xref.rb', line 169

def list_item_value(entry, counter, depth, opts)
  if depth > 2
    label = counter.increment(entry).listlabel(entry.parent, depth)
    s = semx(entry, label)
    base = @c.decode(opts[:prev_label].gsub(%r{<[^>]+>}, "")).split(/\)\s*/) # List a) 1.1.1
    label = "#{base[-1].sub(/^の/,'')}#{clausesep}#{label}"
    [label, opts[:prev_label] + delim_wrap(clausesep) + s]
  else
    super
  end
end

#main_anchor_names(xml) ⇒ Object



120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/jis/xref.rb', line 120

def main_anchor_names(xml)
  n = Counter.new(0, { numerals: @autonumbering_style })
  clause_order_main(xml).each do |a|
    xml.xpath(ns(a[:path])).each do |c|
      section_names(c, n, 1)
      a[:multi] or break
    end
  end
end

#section_names(clause, num, lvl) ⇒ Object



115
116
117
118
# File 'lib/isodoc/jis/xref.rb', line 115

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

#subfigure_anchor(elem, sublabel, label, klass, container: false) ⇒ Object

taken from isodoc to override ISO



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/isodoc/jis/xref.rb', line 64

def subfigure_anchor(elem, sublabel, label, klass, container: false)
  figlabel = fig_subfig_label(label, sublabel)
  @anchors[elem["id"]] = anchor_struct(
    figlabel, elem, @labels[klass] || klass.capitalize, klass,
    { unnumb: elem["unnumbered"], container: }
  ) 
  if elem["unnumbered"] != "true"
    x = semx(elem, sublabel)
    @anchors[elem["id"]][:label] = x
    @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + 
      subfigure_separator(markup: true) + x + delim_wrap(subfigure_delim)
  end
end

#subfigure_delimObject



59
60
61
# File 'lib/isodoc/jis/xref.rb', line 59

def subfigure_delim
  ")"
end

#subfigure_label(subfignum) ⇒ Object



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

def subfigure_label(subfignum)
  subfignum.zero? and return
  (subfignum + 96).chr
end