Class: OPDS::Entry
Overview
Represents a catalog entry
Instance Attribute Summary collapse
-
#authors ⇒ Array
readonly
Entry parsed authors.
-
#categories ⇒ Array
readonly
Categories found.
-
#content ⇒ String
readonly
Content found.
-
#contributors ⇒ Array
readonly
Entry parsed contributors.
-
#dcmetas ⇒ Hash
readonly
Hash of found dublin core metadata found in the entry.
-
#id ⇒ String
readonly
Entry id.
-
#links ⇒ OPDS::Support::LinkSet
readonly
Set of links found in the entry.
-
#published ⇒ Date
readonly
Entry published date.
-
#raw_doc ⇒ Nokogiri::XML::Document
readonly
“Raw” Nokogiri document used while parsing.
-
#rights ⇒ String
readonly
Entry right.
-
#subtitle ⇒ String
readonly
Entry subtitle.
-
#summary ⇒ String
readonly
Entry summary.
-
#title ⇒ String
readonly
Entry title.
-
#updated ⇒ Date
readonly
Entry updated date.
Class Method Summary collapse
-
.from_nokogiri(content, namespaces = nil, browser = OPDS::Support::Browser.new) ⇒ Entry
Create an entry from a nokogiri fragment.
Instance Method Summary collapse
-
#acquisition_links ⇒ Array
Acquisition link subset.
-
#author ⇒ Hash
First Author.
-
#complete_url ⇒ String
URL to the complete entry.
-
#initialize(browser = OPDS::Support::Browser.new) ⇒ Entry
constructor
A new instance of Entry.
- #inspect ⇒ Object
-
#partial? ⇒ boolean
Is it a partial atom entry ?.
-
#serialize! ⇒ Object
Read the provided document into the entry struct.
Methods included from Logging
Constructor Details
#initialize(browser = OPDS::Support::Browser.new) ⇒ Entry
Returns a new instance of Entry.
39 40 41 |
# File 'lib/opds/entry.rb', line 39 def initialize(browser=OPDS::Support::Browser.new) @browser=browser end |
Instance Attribute Details
#authors ⇒ Array (readonly)
Returns entry parsed authors.
21 22 23 |
# File 'lib/opds/entry.rb', line 21 def @authors end |
#categories ⇒ Array (readonly)
Returns Categories found.
30 31 32 |
# File 'lib/opds/entry.rb', line 30 def categories @categories end |
#content ⇒ String (readonly)
Returns content found.
32 33 34 |
# File 'lib/opds/entry.rb', line 32 def content @content end |
#contributors ⇒ Array (readonly)
Returns entry parsed contributors.
23 24 25 |
# File 'lib/opds/entry.rb', line 23 def contributors @contributors end |
#dcmetas ⇒ Hash (readonly)
Returns Hash of found dublin core metadata found in the entry.
28 29 30 |
# File 'lib/opds/entry.rb', line 28 def @dcmetas end |
#id ⇒ String (readonly)
Returns entry id.
13 14 15 |
# File 'lib/opds/entry.rb', line 13 def id @id end |
#links ⇒ OPDS::Support::LinkSet (readonly)
Returns Set of links found in the entry.
25 26 27 |
# File 'lib/opds/entry.rb', line 25 def links @links end |
#published ⇒ Date (readonly)
Returns entry published date.
17 18 19 |
# File 'lib/opds/entry.rb', line 17 def published @published end |
#raw_doc ⇒ Nokogiri::XML::Document (readonly)
“Raw” Nokogiri document used while parsing. It might useful to access atom foreign markup
9 10 11 |
# File 'lib/opds/entry.rb', line 9 def raw_doc @raw_doc end |
#rights ⇒ String (readonly)
Returns entry right.
34 35 36 |
# File 'lib/opds/entry.rb', line 34 def rights @rights end |
#subtitle ⇒ String (readonly)
Returns entry subtitle.
36 37 38 |
# File 'lib/opds/entry.rb', line 36 def subtitle @subtitle end |
#summary ⇒ String (readonly)
Returns entry summary.
19 20 21 |
# File 'lib/opds/entry.rb', line 19 def summary @summary end |
#title ⇒ String (readonly)
Returns entry title.
11 12 13 |
# File 'lib/opds/entry.rb', line 11 def title @title end |
#updated ⇒ Date (readonly)
Returns entry updated date.
15 16 17 |
# File 'lib/opds/entry.rb', line 15 def updated @updated end |
Class Method Details
.from_nokogiri(content, namespaces = nil, browser = OPDS::Support::Browser.new) ⇒ Entry
Create an entry from a nokogiri fragment
48 49 50 51 52 53 54 |
# File 'lib/opds/entry.rb', line 48 def self.from_nokogiri(content,namespaces=nil, browser=OPDS::Support::Browser.new) z=self.new browser z.instance_variable_set('@raw_doc',content) z.instance_variable_set('@namespaces',namespaces) z.serialize! z end |
Instance Method Details
#acquisition_links ⇒ Array
Returns acquisition link subset.
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/opds/entry.rb', line 155 def acquisition_links acq=[] rel_start='http://opds-spec.org/acquisition' links.by(:rel).each do |k,lnk| if !k.nil? && k[0,rel_start.size]==rel_start lnk.each {|l| acq.push l} end end acq end |
#author ⇒ Hash
First Author
134 135 136 |
# File 'lib/opds/entry.rb', line 134 def .first end |
#complete_url ⇒ String
accessor to the complete entry
Returns URL to the complete entry.
148 149 150 151 152 |
# File 'lib/opds/entry.rb', line 148 def complete_url links.by(:rel)['alternate'].find do |l| l[3]=='application/atom+xml;type=entry'||l[3]=='application/atom+xml' end unless !partial? end |
#inspect ⇒ Object
166 167 168 |
# File 'lib/opds/entry.rb', line 166 def inspect "#<#{self.class}:0x#{self.object_id.abs.to_s(16)} #{instance_variables.reject{|e| e=='@raw_doc' }.collect{|e| "#{e}=#{instance_variable_get(e).inspect}"}.join(' ')} >" end |
#partial? ⇒ boolean
Is it a partial atom entry ?
140 141 142 143 144 |
# File 'lib/opds/entry.rb', line 140 def partial? links.by(:rel)['alternate'].any? do |l| l[3]=='application/atom+xml'||l[3]=='application/atom+xml;type=entry' end end |
#serialize! ⇒ Object
really make private
Read the provided document into the entry struct
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/opds/entry.rb', line 59 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 |auth| { :name => text(raw_doc.at('./xmlns:author/xmlns:name',@namespaces)), :uri => text(raw_doc.at('./xmlns:author/xmlns:uri',@namespaces)), :email => text(raw_doc.at('./xmlns:author/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 |