Class: EeePub::NCX

Inherits:
ContainerItem show all
Defined in:
lib/eeepub/ncx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ContainerItem

#initialize, #save, #set_values, #to_xml

Constructor Details

This class inherits a constructor from EeePub::ContainerItem

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def depth
  @depth
end

#doc_titleObject

Returns the value of attribute doc_title.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def doc_title
  @doc_title
end

#max_page_numberObject

Returns the value of attribute max_page_number.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def max_page_number
  @max_page_number
end

Returns the value of attribute nav_map.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def nav_map
  @nav_map
end

#total_page_countObject

Returns the value of attribute total_page_count.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def total_page_count
  @total_page_count
end

#uidObject

Returns the value of attribute uid.



3
4
5
# File 'lib/eeepub/ncx.rb', line 3

def uid
  @uid
end

Instance Method Details

#build_head(builder) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eeepub/ncx.rb', line 27

def build_head(builder)
  builder.head do
    {
      :uid => uid,
      :depth => depth,
      :totalPageCount => total_page_count,
      :maxPageNumber => max_page_number
    }.each do |k, v|
      builder.meta :name => "dtb:#{k}", :content => v
    end
  end
end

#build_nav_map(builder) ⇒ Object



40
41
42
43
44
# File 'lib/eeepub/ncx.rb', line 40

def build_nav_map(builder)
  builder.navMap do
    builder_nav_point(builder, nav_map)
  end
end

#build_xml(builder) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/eeepub/ncx.rb', line 18

def build_xml(builder)
  builder.declare! :DOCTYPE, :ncx, :PUBLIC, "-//NISO//DTD ncx 2005-1//EN", "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"
  builder.ncx :xmlns => "http://www.daisy.org/z3986/2005/ncx/", :version => "2005-1" do
    build_head(builder)
    builder.docTitle { builder.text doc_title }
    build_nav_map(builder)
  end
end

#builder_nav_point(builder, nav_point, play_order = 1) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/eeepub/ncx.rb', line 46

def builder_nav_point(builder, nav_point, play_order = 1)
  case nav_point
  when Array
    nav_point.each do |point|
      play_order = builder_nav_point(builder, point, play_order)
    end
  when Hash
    id = nav_point[:id] || "navPoint-#{play_order}"
    builder.navPoint :id => id, :playOrder => play_order do
      builder.navLabel { builder.text nav_point[:label] }
      builder.content :src => nav_point[:content]
      play_order += 1
      if nav_point[:nav]
        play_order = builder_nav_point(builder, nav_point[:nav], play_order)
      end
    end
  else
    raise "nav_point must be Array or Hash"
  end
  play_order
end