Sha256: a4304ba1362099b77ba0777076fd33e773e625de5b47b14b59f60716f4b83e5a
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
# encoding: utf-8 # Copyright (c) 2008-2017 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, # KADO Masanori # # This program is free software. # You can distribute or modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # module ReVIEW # Secion Counter class # class SecCounter def initialize(n, chapter) @chapter = chapter reset(n) end def reset(n) @counter = Array.new(n, 0) end def inc(level) n = level - 2 if n >= 0 @counter[n] += 1 end if @counter.size > n (n+1..@counter.size).each do |i| @counter[i] = 0 end end end def anchor(level) str = "#{@chapter.format_number(false)}" 0.upto(level-2) do |i| str << "-#{@counter[i]}" end str end def prefix(level, secnolevel) return nil if @chapter.number.blank? if level == 1 if secnolevel >= 1 if @chapter.is_a? ReVIEW::Book::Part num = @chapter.number return "#{I18n.t('part', num)}#{I18n.t("chapter_postfix")}" else return "#{@chapter.format_number}#{I18n.t("chapter_postfix")}" end end elsif secnolevel >= level prefix = '' if @chapter.is_a? ReVIEW::Book::Part prefix = I18n.t('part_short', @chapter.number) else prefix = @chapter.format_number(false) end 0.upto(level - 2) do |i| prefix << ".#{@counter[i]}" end prefix << I18n.t("chapter_postfix") return prefix end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
review-2.3.0 | lib/review/sec_counter.rb |