Class: DjVuNumberer

Inherits:
DjVuTools show all
Defined in:
lib/djvu-tools/djvu-numberer.rb

Overview

Page title management for page number generation

Constant Summary

Constants inherited from DjVuTools

DjVuTools::VERSION

Instance Method Summary collapse

Methods inherited from DjVuTools

#run

Constructor Details

#initialize(file) ⇒ DjVuNumberer

Returns a new instance of DjVuNumberer.

See Also:

  • ObjectName#method


5
6
7
8
# File 'lib/djvu-tools/djvu-numberer.rb', line 5

def initialize file
  super
  @sections = []
end

Instance Method Details

#add_section(section) ⇒ Object

Add a labeled section.

Parameters:

  • section (Hash)

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/djvu-tools/djvu-numberer.rb', line 13

def add_section section

  section[:delta] ||= 1

  if section[:start].nil?
    raise ArgumentError, 'Cannot label a range of pages with the same title' if ( section[:range].max - section[:range].min > 0 )
    section[:range].each { |n| @djvu.title_page n, section[:title]  }
  else
    section[:range].each_with_index do |n, i|
      number = section[:start] + i * section[:delta].to_i
      number =
        case section[:type]
        when :arabic
          number.to_s
        when :upper_roman
          RomanNumerals::to_roman(number).upcase
        when :lower_roman
          RomanNumerals::to_roman(number).downcase
        end
      @djvu.title_page n, "#{section[:prefix]}#{number}#{section[:suffix]}"
    end
  end
end