Class: Asciidoctor::PDF::IndexCatalog

Inherits:
Object
  • Object
show all
Includes:
TextTransformer
Defined in:
lib/asciidoctor/pdf/index_catalog.rb

Constant Summary collapse

LeadingAlphaRx =
/^\p{Alpha}/

Constants included from TextTransformer

TextTransformer::BareClassRx, TextTransformer::ContiguousCharsRx, TextTransformer::Hyphen, TextTransformer::LowerAlphaChars, TextTransformer::PCDATAFilterRx, TextTransformer::SmallCapsChars, TextTransformer::SoftHyphen, TextTransformer::TagFilterRx, TextTransformer::WordRx, TextTransformer::XMLMarkupRx

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextTransformer

#capitalize_words, #capitalize_words_pcdata, #hyphenate_words, #hyphenate_words_pcdata, #lowercase_pcdata, #smallcaps, #smallcaps_pcdata, #transform_text, #uppercase_pcdata

Constructor Details

#initializeIndexCatalog

Returns a new instance of IndexCatalog.



12
13
14
15
16
17
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 12

def initialize
  @categories = {}
  @start_page_number = 1
  @dests = {}
  @sequence = 0
end

Instance Attribute Details

#start_page_numberObject

Returns the value of attribute start_page_number.



10
11
12
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 10

def start_page_number
  @start_page_number
end

Instance Method Details

#categoriesObject



72
73
74
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 72

def categories
  @categories.values.sort
end

#empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 68

def empty?
  @categories.empty?
end

#find_category(name) ⇒ Object



53
54
55
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 53

def find_category name
  @categories[name]
end

#init_category(name) ⇒ Object



48
49
50
51
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 48

def init_category name
  name = '@' unless LeadingAlphaRx.match? name
  @categories[name] ||= IndexTermCategory.new name
end


61
62
63
64
65
66
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 61

def link_dest_to_page anchor, physical_page_number
  if (dest = @dests[anchor])
    virtual_page_number = (dest[:page_sortable] = physical_page_number) - (@start_page_number - 1)
    dest[:page] = (virtual_page_number < 1 ? (RomanNumeral.new physical_page_number, :lower) : virtual_page_number).to_s
  end
end

#next_anchor_nameObject



19
20
21
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 19

def next_anchor_name
  %(__indexterm-#{@sequence += 1})
end

#store_dest(dest) ⇒ Object



57
58
59
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 57

def store_dest dest
  @dests[dest[:anchor]] = dest
end

#store_primary_term(name, dest = nil) ⇒ Object



33
34
35
36
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 33

def store_primary_term name, dest = nil
  store_dest dest if dest
  (init_category name.chr.upcase).store_term name, dest
end

#store_secondary_term(primary_name, secondary_name, dest = nil) ⇒ Object



38
39
40
41
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 38

def store_secondary_term primary_name, secondary_name, dest = nil
  store_dest dest if dest
  (store_primary_term primary_name).store_term secondary_name, dest
end

#store_term(names, dest) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 23

def store_term names, dest
  if (num_terms = names.size) > 2
    store_tertiary_term names[0], names[1], names[2], dest
  elsif num_terms == 2
    store_secondary_term names[0], names[1], dest
  elsif num_terms == 1
    store_primary_term names[0], dest
  end
end

#store_tertiary_term(primary_name, secondary_name, tertiary_name, dest) ⇒ Object



43
44
45
46
# File 'lib/asciidoctor/pdf/index_catalog.rb', line 43

def store_tertiary_term primary_name, secondary_name, tertiary_name, dest
  store_dest dest
  (store_secondary_term primary_name, secondary_name).store_term tertiary_name, dest
end