class Epuber::OpfFile
Constants
- LANDMARKS_MAP
-
reversed map of generator’s map
Attributes
@return [Nokogiri::XML::Document]
@return [Array<GuideItem>]
@return [Nokogiri::XML::Node, nil]
@return [Hash<String, ManifestItem>]
@return [Nokogiri::XML::Node, nil]
@return [Nokogiri::XML::Node, nil]
@return [Nokogiri::XML::Node, nil]
@return [Array<SpineItem>]
Public Class Methods
Source
# File lib/epuber/from_file/opf_file.rb, line 126 def initialize(xml) @document = Nokogiri::XML(xml) @document.remove_namespaces! @package = @document.at_css('package') @metadata = @document.at_css('package metadata') @manifest = @document.at_css('package manifest') @spine = @document.at_css('package spine') @manifest_items = @document.css('package manifest item') .map { |node| ManifestItem.from_node(node) } .map { |item| [item.id, item] } .to_h @spine_items = @document.css('package spine itemref') .map { |node| SpineItem.from_node(node) } @guide_items = @document.css('package guide reference') .map { |node| GuideItem.from_node(node) } end
@param [String] document
Public Instance Methods
Source
# File lib/epuber/from_file/opf_file.rb, line 186 def find_refines(id, property) @metadata.at_css(%(meta[refines="##{id}"][property="#{property}"]))&.text end
Find meta refines in EPUB 3 metadata
@param [String] id @param [String] property
@return [String, nil]
Source
# File lib/epuber/from_file/opf_file.rb, line 175 def identifiers @metadata.css('identifier') end
Return all identifiers from EPUB metadata
@return [Array<Nokogiri::XML::Node>]
Source
# File lib/epuber/from_file/opf_file.rb, line 209 def manifest_file_by_href(href) # remove anchor href = href.sub(/#.*$/, '') item = @manifest_items.find { |_, i| i.href == href }&.last raise "Manifest item with href #{href.inspect} not found" unless item item end
Find file in <manifest> by href. Throws exception when not found.
@param [String] href
@return [ManifestItem]
Source
# File lib/epuber/from_file/opf_file.rb, line 196 def manifest_file_by_id(id) item = @manifest_items[id] raise "Manifest item with id #{id.inspect} not found" unless item item end
Find file in <manifest> by id. Throws exception when not found.
@param [String] id
@return [ManifestItem]
Source
# File lib/epuber/from_file/opf_file.rb, line 164 def raw_unique_identifier id = @package['unique-identifier'] return unless id @metadata.at_css(%(identifier[id="#{id}"]))&.text end
Returns main unique identifier of this EPUB
@return [String, nil]