Class: OPDS::OPDSParser

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/opds/parser.rb

Overview

Class in charge of discovering the type of the given text stream. It will dispatch the pre-parsed atom content to the desired class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, log

Constructor Details

#initialize(opts = {}) ⇒ OPDSParser



14
15
16
17
# File 'lib/opds/parser.rb', line 14

def initialize(opts={})
	@sniffed_type=nil
	self.options=opts.merge({})
end

Instance Attribute Details

#optionsHash



11
12
13
# File 'lib/opds/parser.rb', line 11

def options
  @options
end

#sniffed_typeSymbol (readonly)



13
14
15
# File 'lib/opds/parser.rb', line 13

def sniffed_type
  @sniffed_type
end

Instance Method Details

#parse(content, browser = nil) ⇒ NavigationFeed, ...

Parse a text stream



23
24
25
26
27
28
29
30
31
# File 'lib/opds/parser.rb', line 23

def parse(content,browser=nil)
	@ret=Nokogiri::XML(content)
	@sniffed_type=sniff(@ret)
	case @sniffed_type
	when :acquisition then return OPDS::AcquisitionFeed.from_nokogiri(@ret,browser)
	when :navigation then return OPDS::NavigationFeed.from_nokogiri(@ret,browser)
	when :entry then return OPDS::Entry.from_nokogiri(@ret,nil,browser)
	end
end