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

Returns a new instance of 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

Returns parsing options.

Returns:

  • (Hash)

    parsing options



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

def options
  @options
end

#sniffed_typeSymbol (readonly)

Returns last parsed stream sniffed type (:acquisition,:navigation,:entry).

Returns:

  • (Symbol)

    last parsed stream sniffed type (:acquisition,:navigation,:entry)



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

Parameters:

  • content (String)

    text stream

  • browser (OPDS::Support::Browser) (defaults to: nil)

    an optional compatible browser to use

Returns:



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