Class: IsoDoc::Function::XrefGen::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/isodoc/function/xref_counter.rb

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



14
15
16
17
18
# File 'lib/isodoc/function/xref_counter.rb', line 14

def initialize
  @num = 0
  @letter = ""
  @subseq = ""
end

Instance Method Details

#increment(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/isodoc/function/xref_counter.rb', line 20

def increment(node)
  return self if node["unnumbered"]
  if node["subsequence"] != @subseq
    @subseq = node["subsequence"]
    @num += 1
    @letter = node["subsequence"] ? "a" : ""
  else
    if @letter.empty?
      @num += 1
    else
      @letter = (@letter.ord + 1).chr.to_s
    end
  end
  self
end

#listlabel(depth) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/isodoc/function/xref_counter.rb', line 40

def listlabel(depth)
  return @num.to_s if [2, 7].include? depth
  return (96 + @num).chr.to_s if [1, 6].include? depth
  return (64 + @num).chr.to_s if [4, 9].include? depth
  return RomanNumerals.to_roman(@num).downcase if [3, 8].include? depth
  return RomanNumerals.to_roman(@num).upcase if [5, 10].include? depth
  return @num.to_s
end


36
37
38
# File 'lib/isodoc/function/xref_counter.rb', line 36

def print
  "#{@num}#{@letter}"
end