Module: EPUB::Parser::Utils

Included in:
ContentDocument, OCF, Publication
Defined in:
lib/epub/parser/utils.rb

Class Method Summary collapse

Class Method Details

.extract_attribute(element, name, prefix = nil) ⇒ String

TODO:

Refinement Nokogiri::XML::Node instead of use this method after Ruby 2.0 becomes popular

Extract the value of attribute of element

Parameters:

  • element (Nokogiri::XML::Element)
  • name (String)

    name of attribute excluding namespace prefix

  • prefix (String, nil) (defaults to: nil)

    XML namespace prefix in NAMESPACES keys

Returns:

  • (String)

    value of attribute when the attribute exists

  • nil when the attribute doesn’t exist



13
14
15
16
# File 'lib/epub/parser/utils.rb', line 13

def extract_attribute(element, name, prefix=nil)
  attr = element.attribute_with_ns(name, EPUB::NAMESPACES[prefix])
  attr.nil? ? nil : attr.value
end