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.



6
7
8
9
10
# File 'lib/isodoc/function/xref_counter.rb', line 6

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

Instance Method Details

#increment(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/isodoc/function/xref_counter.rb', line 12

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



32
33
34
35
36
37
38
39
# File 'lib/isodoc/function/xref_counter.rb', line 32

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


28
29
30
# File 'lib/isodoc/function/xref_counter.rb', line 28

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