Class: Ape::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/ape/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, doc_uri = nil) ⇒ Collection

Returns a new instance of Collection.

Raises:

  • (SyntaxError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ape/collection.rb', line 9

def initialize(input, doc_uri = nil)
  @input = input
  @accept = []
  @title = REXML::XPath.first(input, './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(input.attributes['href'], input)
  else
    @href = input.attributes['href']
  end

  # now we have to go looking for the accept
  @accept = []
  REXML::XPath.each(input, './app:accept', Names::XmlNamespaces) do |a|
    @accept << a.texts.join
  end

  @accept = [ Names::AtomEntryMediaType ] if @accept.empty?
end

Instance Attribute Details

#acceptObject (readonly)

Returns the value of attribute accept.



7
8
9
# File 'lib/ape/collection.rb', line 7

def accept
  @accept
end

#hrefObject (readonly)

Returns the value of attribute href.



7
8
9
# File 'lib/ape/collection.rb', line 7

def href
  @href
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/ape/collection.rb', line 7

def title
  @title
end

Instance Method Details

#catsesObject

the name is supposed to suggest multiple instances of “categories”



43
44
45
# File 'lib/ape/collection.rb', line 43

def catses
  REXML::XPath.match(@input, './app:categories', Names::XmlNamespaces)
end

#to_sObject



34
35
36
# File 'lib/ape/collection.rb', line 34

def to_s
  @input.to_s
end

#to_strObject



38
39
40
# File 'lib/ape/collection.rb', line 38

def to_str
  to_s
end