class Epuber::NavFile
Constants
- LANDMARKS_MAP
- MODE_NCX
- MODE_XHTML
Attributes
document[R]
@return [Nokogiri::XML::Document]
items[R]
@return [Array<NavItem>]
landmarks[R]
@return [Array<LandmarkItem>, nil]
mode[R]
@return [:ncx, :xhtml]
Public Class Methods
new(document, mode)
click to toggle source
@param [string] document @param [:ncx, :xhtml] mode
# File lib/epuber/from_file/nav_file.rb, line 95 def initialize(document, mode) raise ArgumentError, 'mode must be :ncx or :xhtml' unless [MODE_NCX, MODE_XHTML].include?(mode) @document = Nokogiri::XML(document) @document.remove_namespaces! @mode = mode @items = _parse @landmarks = _parse_landmarks end
Public Instance Methods
find_by_href(href, ignore_fragment: false)
click to toggle source
@param [String] href @param [Boolean] ignore_fragment
@return [NavItem, nil]
# File lib/epuber/from_file/nav_file.rb, line 112 def find_by_href(href, ignore_fragment: false) @items.find { |item| item.find_by_href(href, ignore_fragment: ignore_fragment) } end
Private Instance Methods
_parse()
click to toggle source
@return [Array<NavItem>]
# File lib/epuber/from_file/nav_file.rb, line 146 def _parse if @mode == MODE_XHTML @document.css('nav[type="toc"] > ol > li') .map { |point| _parse_nav_xhtml_item(point) } elsif @mode == MODE_NCX @document.css('navMap > navPoint') .map { |point| _parse_nav_ncx_item(point) } end end
_parse_landmarks()
click to toggle source
# File lib/epuber/from_file/nav_file.rb, line 156 def _parse_landmarks return nil if @mode != MODE_XHTML @document.css('nav[type="landmarks"] > ol > li > a') .map { |node| LandmarkItem.from_node(node) } end