lib/opds/parser.rb
# Sniff a provided nokogiri document to detect it's type 
# @param doc [Nokogiri::XML::Document] Document to sniff
# @return [:acquisition, :navigation, :entry, nil] sniffed type
Sniff a provided nokogiri document to detect it's type
Sniff a provided nokogiri document to detect it ' s type
def sniff(doc)
			return :entry if doc.root.name=='entry'
			entries = doc.xpath('/xmlns:feed/xmlns:entry',doc.root.namespaces)
			if entries.size > 0
				return :acquisition if entries.all? do |entry|
					entry.xpath('xmlns:link').any? do |link|  
						l=link.attributes['rel']
						unless l.nil?
							l.value.include?('http://opds-spec.org/acquisition') 
						else
							false
						end
					end
				end
				return :navigation
			end
			return nil
		rescue 
			nil
		end
def sniff ( doc ) return :entry if doc . root . name == 'entry' entries = doc . xpath ( '/xmlns:feed/xmlns:entry' , doc . root . namespaces ) if entries . size > 0 return :acquisition if entries . all? do | entry | entry . xpath ( 'xmlns:link' ) . any? do | link | l = link . attributes [ 'rel' ] unless l . nil? l . value . include? ( 'http://opds-spec.org/acquisition' ) else false end end end return :navigation end return nil rescue nil end
Sniff a provided nokogiri document to detect it's type
Sniff a provided nokogiri document to detect it ' s type
None
:acquisition, :navigation, :entry, nil
doc
Document to sniff
Document to sniff