Class: Ape::CollElement
- Inherits:
-
Object
- Object
- Ape::CollElement
- Defined in:
- lib/ape/coll_element.rb
Constant Summary collapse
- @@mime_re =
%r{^(.*)/(.*)$}
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
Instance Method Summary collapse
-
#accept?(mime_type) ⇒ Boolean
check if the collection accepts a given mime type; watch out for wildcards.
-
#catses ⇒ Object
the name is supposed to suggest multiple instances of “categories”.
-
#initialize(el, doc_uri = nil) ⇒ CollElement
constructor
A new instance of CollElement.
Constructor Details
#initialize(el, doc_uri = nil) ⇒ CollElement
Returns a new instance of CollElement.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ape/coll_element.rb', line 18 def initialize(el, doc_uri = nil) @xml = el @accept = [] @title = REXML::XPath.first(el, './atom:title', Names::XmlNamespaces) # sigh, RNC validation *should* take care of this raise(SyntaxError, "Collection is missing required 'atom:title'") unless @title @title = @title.texts.join if doc_uri uris = AtomURI.new(doc_uri) @href = uris.absolutize(el.attributes['href'], el) else @href = el.attributes['href'] end # now we have to go looking for the accept @accept = REXML::XPath.match(@xml, './app:accept/(text)', Names::XmlNamespaces) @accept = [ Names::AtomEntryMediaType ] if @accept.empty? end |
Instance Attribute Details
#accept ⇒ Object (readonly)
Returns the value of attribute accept.
11 12 13 |
# File 'lib/ape/coll_element.rb', line 11 def accept @accept end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
11 12 13 |
# File 'lib/ape/coll_element.rb', line 11 def href @href end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/ape/coll_element.rb', line 11 def title @title end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
11 12 13 |
# File 'lib/ape/coll_element.rb', line 11 def xml @xml end |
Class Method Details
.find_colls(source, doc_uri = nil) ⇒ Object
13 14 15 16 |
# File 'lib/ape/coll_element.rb', line 13 def CollElement::find_colls(source, doc_uri = nil) els = REXML::XPath.match(source, '//app:collection', Names::XmlNamespaces) els.map { |el| CollElement.new(el, doc_uri) } end |
Instance Method Details
#accept?(mime_type) ⇒ Boolean
check if the collection accepts a given mime type; watch out for wildcards
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ape/coll_element.rb', line 40 def accept?(mime_type) if mime_type =~ @@mime_re p1, p2 = $1, $2 else return false # WTF? end @accept.each do |pat| pat = pat.to_s # working around REXML ticket 164 if pat =~ @@mime_re if ($1 == p1 || $1 == "*") && ($2 == p2 || $2 == "*") return true elsif ((pat == Names::AtomMediaType && mime_type == Names::AtomFeedMediaType) || (pat == Names::AtomFeedMediaType && mime_type == Names::AtomMediaType)) return true end end end return false end |
#catses ⇒ Object
the name is supposed to suggest multiple instances of “categories”
61 62 63 |
# File 'lib/ape/coll_element.rb', line 61 def catses REXML::XPath.match(@xml, './app:categories', Names::XmlNamespaces) end |