lib/opds/entry.rb
# Read the provided document into the entry struct 
# @private
# @todo really make private
Read the provided document into the entry struct
Read the provided document into the entry struct
def serialize!
			@namespaces=raw_doc.root.namespaces if @namespaces.nil?
			@authors=[]
			@raw_doc=raw_doc.at('./xmlns:entry',@namespaces) if raw_doc.at('./xmlns:entry',@namespaces)
			@title=text(raw_doc.at('./xmlns:title',@namespaces))
			@id=text(raw_doc.at('./xmlns:id',@namespaces))
			@summary=text(raw_doc.at('./xmlns:summary',@namespaces))
			d=text(raw_doc.at('./xmlns:updated',@namespaces))
			@updated=DateTime.parse(d) unless d.nil?
			d=text(raw_doc.at('./xmlns:published',@namespaces))
			@published=DateTime.parse(d) unless d.nil?
			@authors=raw_doc.xpath('./xmlns:author',@namespaces).collect do |author|
				{
					:name => text(author.at('./xmlns:name',@namespaces)),
					:uri => text(author.at('./xmlns:uri',@namespaces)),
					:email => text(author.at('./xmlns:email',@namespaces))
				}
			end
			@links=OPDS::Support::LinkSet.new @browser
			raw_doc.xpath('./xmlns:link',@namespaces).each do |n|
				text=nil
				text=n.attributes['title'].value unless n.attributes['title'].nil?
				link=n.attributes['href'].value
				type=n.attributes['type'].value unless n.attributes['type'].nil?
				price=nil
				currency=nil
				@namespaces['opds']||='http://opds-spec.org/2010/catalog'
				types=n.search('.//opds:indirectAcquisition',@namespaces).map{|b| b['type']}
				type=[type,types].flatten.compact unless types.nil? || types.empty?
				oprice=n.at('./opds:price',@namespaces)
				if oprice
					price=text(oprice)
					currency=oprice.attributes['currencycode'].value unless oprice.attributes['currencycode'].nil?
				end
				unless n.attributes['rel'].nil?
					n.attributes['rel'].value.split.each do |rel|
						@links.push(rel,link,text,type,price,currency)
					end
				else
					@links.push(nil,link,text,type,price,currency)
				end
			end
			@dcmetas=Hash.new
			prefs=@namespaces.reject{|_,v| !%W[http://purl.org/dc/terms/ http://purl.org/dc/elements/1.1/].include?v}
			prefs.keys.map{|p| p.split(':').last}.each do |pref|
				raw_doc.xpath('./'+pref+':*',@namespaces).each do |n|
					@dcmetas[n.name]=[] unless  @dcmetas[n.name]
					@dcmetas[n.name].push [n.text, n]
				end
			end
			@categories=raw_doc.xpath('./xmlns:category',@namespaces).collect do |n|
				[text(n.attributes['label']),text(n.attributes['term'])]
			end
			@content=raw_doc.at('./xmlns:content',@namespaces).to_s
			@contributors=raw_doc.xpath('./xmlns:contributor',@namespaces).collect do |auth|
				{
					:name => text(raw_doc.at('./xmlns:contributor/xmlns:name',@namespaces)),
					:uri => text(raw_doc.at('./xmlns:contributor/xmlns:uri',@namespaces)),
					:email => text(raw_doc.at('./xmlns:contributor/xmlns:email',@namespaces))
				}
			end
			@rights=text(raw_doc.at('./xmlns:rights',@namespaces))
			@subtitle=text(raw_doc.at('./xmlns:rights',@namespaces))
		end
def serialize! @namespaces = raw_doc . root . namespaces if @namespaces . nil? @authors = [ ] @raw_doc = raw_doc . at ( './xmlns:entry' , @namespaces ) if raw_doc . at ( './xmlns:entry' , @namespaces ) @title = text ( raw_doc . at ( './xmlns:title' , @namespaces ) ) @id = text ( raw_doc . at ( './xmlns:id' , @namespaces ) ) @summary = text ( raw_doc . at ( './xmlns:summary' , @namespaces ) ) d = text ( raw_doc . at ( './xmlns:updated' , @namespaces ) ) @updated = DateTime . parse ( d ) unless d . nil? d = text ( raw_doc . at ( './xmlns:published' , @namespaces ) ) @published = DateTime . parse ( d ) unless d . nil? @authors = raw_doc . xpath ( './xmlns:author' , @namespaces ) . collect do | author | { :name => text ( author . at ( './xmlns:name' , @namespaces ) ) , :uri => text ( author . at ( './xmlns:uri' , @namespaces ) ) , :email => text ( author . at ( './xmlns:email' , @namespaces ) ) } end @links = OPDS :: Support :: LinkSet . new @browser raw_doc . xpath ( './xmlns:link' , @namespaces ) . each do | n | text = nil text = n . attributes [ 'title' ] . value unless n . attributes [ 'title' ] . nil? link = n . attributes [ 'href' ] . value type = n . attributes [ 'type' ] . value unless n . attributes [ 'type' ] . nil? price = nil currency = nil @namespaces [ 'opds' ] ||= 'http://opds-spec.org/2010/catalog' types = n . search ( './/opds:indirectAcquisition' , @namespaces ) . map { | b | b [ 'type' ] } type = [ type , types ] . flatten . compact unless types . nil? || types . empty? oprice = n . at ( './opds:price' , @namespaces ) if oprice price = text ( oprice ) currency = oprice . attributes [ 'currencycode' ] . value unless oprice . attributes [ 'currencycode' ] . nil? end unless n . attributes [ 'rel' ] . nil? n . attributes [ 'rel' ] . value . split . each do | rel | @links . push ( rel , link , text , type , price , currency ) end else @links . push ( nil , link , text , type , price , currency ) end end @dcmetas = Hash . new prefs = @namespaces . reject { | _ , v | ! %W[ http://purl.org/dc/terms/ http://purl.org/dc/elements/1.1/ ] . include? v } prefs . keys . map { | p | p . split ( ':' ) . last } . each do | pref | raw_doc . xpath ( './' + pref + ':*' , @namespaces ) . each do | n | @dcmetas [ n . name ] = [ ] unless @dcmetas [ n . name ] @dcmetas [ n . name ] . push [ n . text , n ] end end @categories = raw_doc . xpath ( './xmlns:category' , @namespaces ) . collect do | n | [ text ( n . attributes [ 'label' ] ) , text ( n . attributes [ 'term' ] ) ] end @content = raw_doc . at ( './xmlns:content' , @namespaces ) . to_s @contributors = raw_doc . xpath ( './xmlns:contributor' , @namespaces ) . collect do | auth | { :name => text ( raw_doc . at ( './xmlns:contributor/xmlns:name' , @namespaces ) ) , :uri => text ( raw_doc . at ( './xmlns:contributor/xmlns:uri' , @namespaces ) ) , :email => text ( raw_doc . at ( './xmlns:contributor/xmlns:email' , @namespaces ) ) } end @rights = text ( raw_doc . at ( './xmlns:rights' , @namespaces ) ) @subtitle = text ( raw_doc . at ( './xmlns:rights' , @namespaces ) ) end
Read the provided document into the entry struct
Read the provided document into the entry struct
private
None
todo
really make private
really make private