Class: Oos4ruby::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/oos4ruby/feed.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries, xml) ⇒ Feed



9
10
11
12
13
14
15
16
17
# File 'lib/oos4ruby/feed.rb', line 9

def initialize(entries, xml)
  @entries = entries
  @xml = xml
  @next = Feed.get_link('next', xml)
  @previous = Feed.get_link 'previous', xml
  @self = Feed.get_link 'self', xml
  @size = REXML::XPath.first(xml, "./os:itemsPerPage/text()", XmlNamespaces)
  @total_size = REXML::XPath.first(xml, "./os:totalResults/text()", XmlNamespaces)
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def entries
  @entries
end

#nextObject (readonly)

Returns the value of attribute next.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def next
  @next
end

#previousObject (readonly)

Returns the value of attribute previous.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def previous
  @previous
end

#sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def size
  @size
end

#total_sizeObject (readonly)

Returns the value of attribute total_size.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def total_size
  @total_size
end

#xmlObject (readonly)

Returns the value of attribute xml.



7
8
9
# File 'lib/oos4ruby/feed.rb', line 7

def xml
  @xml
end

Class Method Details



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oos4ruby/feed.rb', line 19

def self.get_link(rel, xml)
  link = REXML::XPath.first(xml, "./atom:link[@rel=\"#{rel}\"]", XmlNamespaces)
  if link      
    uri = URI.parse link.attributes['href']
    if uri.absolute?
      return uri
    else
      return URI.parse(OOS_URL).merge(uri)
    end      
  end
end

.read(body) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/oos4ruby/feed.rb', line 31

def Feed.read(body)

  feed = nil
  begin
    feed = REXML::Document.new(body, { :raw => nil }).root
    
    entries = REXML::XPath.match(feed, "./atom:entry", XmlNamespaces)      

    entries.map! { |entry| Entry.new(entry) }
    feed = Feed.new( entries, feed )
  rescue => ex
    puts ex.message
    puts ex.backtrace.join("\n")        
  end    

  return feed
end

Instance Method Details

#next?Boolean



61
62
63
# File 'lib/oos4ruby/feed.rb', line 61

def next?    
  !@next.nil?
end

#previous?Boolean



57
58
59
# File 'lib/oos4ruby/feed.rb', line 57

def previous?    
  !@previous.nil?
end


49
50
51
# File 'lib/oos4ruby/feed.rb', line 49

def self_link
  @self
end

#self_link?Boolean



53
54
55
# File 'lib/oos4ruby/feed.rb', line 53

def self_link?
  !@self.nil?
end