Sha256: f6dd25a5d4baa0202406f92078a2df7152040125ff86d112994a554bc6ae137e

Contents?: true

Size: 789 Bytes

Versions: 12

Compression:

Stored size: 789 Bytes

Contents

module EPUB
  class Parser
    module Utils
      # Extract the value of attribute of element
      # 
      # @todo Refinement Nokogiri::XML::Node instead of use this method after Ruby 2.0 becomes popular
      # 
      # @param [Nokogiri::XML::Element] element
      # @param [String] name name of attribute excluding namespace prefix
      # @param [String, nil] prefix XML namespace prefix in {EPUB::Constants::NAMESPACES} keys
      # @return [String] value of attribute when the attribute exists
      # @return nil when the attribute doesn't exist
      def extract_attribute(element, name, prefix=nil)
        attr = element.attribute_with_ns(name, EPUB::NAMESPACES[prefix])
        attr.nil? ? nil : attr.value
      end
      module_function :extract_attribute
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
epub-parser-0.2.0 lib/epub/parser/utils.rb
epub-parser-0.1.9 lib/epub/parser/utils.rb
epub-parser-0.1.8 lib/epub/parser/utils.rb
epub-parser-0.1.7.1 lib/epub/parser/utils.rb
epub-parser-0.1.7 lib/epub/parser/utils.rb
epub-parser-io-0.1.6b lib/epub/parser/utils.rb
epub-parser-io-0.1.6a lib/epub/parser/utils.rb
epub-parser-io-0.1.6 lib/epub/parser/utils.rb
epub-parser-0.1.6 lib/epub/parser/utils.rb
epub-parser-0.1.5 lib/epub/parser/utils.rb
epub-parser-0.1.4 lib/epub/parser/utils.rb
epub-parser-0.1.3 lib/epub/parser/utils.rb