Class: GoogleReader::Entry
- Inherits:
-
Object
- Object
- GoogleReader::Entry
- Defined in:
- lib/google_reader/entry.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #author ⇒ Object
- #categories ⇒ Object
- #has_known_author? ⇒ Boolean
- #hash ⇒ Object
- #href ⇒ Object
- #id ⇒ Object
- #id_node ⇒ Object
-
#initialize(entry) ⇒ Entry
constructor
A new instance of Entry.
- #liking_users ⇒ Object
- #original_id ⇒ Object
- #published_at ⇒ Object
- #source ⇒ Object
- #summary ⇒ Object
- #title ⇒ Object
- #unhtml(text) ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(entry) ⇒ Entry
Returns a new instance of Entry.
6 7 8 |
# File 'lib/google_reader/entry.rb', line 6 def initialize(entry) @entry = entry end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/google_reader/entry.rb', line 14 def ==(other) self.id == other.id end |
#author ⇒ Object
78 79 80 |
# File 'lib/google_reader/entry.rb', line 78 def @entry.search("author name").first.text end |
#categories ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/google_reader/entry.rb', line 35 def categories @entry.search("category").reject do |node| node["scheme"] == "http://www.google.com/reader/" end.map do |node| node["label"] || node["term"] end end |
#has_known_author? ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/google_reader/entry.rb', line 67 def node = @entry.search("author").first return false unless node attr = node.attribute_with_ns("unknown-author", GOOGLE_ATOM_NAMESPACE) return true unless attr # Cater to JRuby + libffi return true if attr.respond_to?(:null?) && attr.null? attr.text != "true" end |
#hash ⇒ Object
10 11 12 |
# File 'lib/google_reader/entry.rb', line 10 def hash self.id.hash end |
#href ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/google_reader/entry.rb', line 59 def href @entry.search("link[rel=alternate]").reject do |node| node["href"].to_s.empty? end.detect do |node| node["type"] == "text/html" end["href"] end |
#id ⇒ Object
18 19 20 |
# File 'lib/google_reader/entry.rb', line 18 def id id_node.text end |
#id_node ⇒ Object
97 98 99 100 101 |
# File 'lib/google_reader/entry.rb', line 97 def id_node nodes = @entry.search("id") return nil if nodes.empty? nodes.first end |
#liking_users ⇒ Object
90 91 92 93 94 95 |
# File 'lib/google_reader/entry.rb', line 90 def liking_users # NOTE: CSS namespaces don't work all that well: must use XPath here @entry.search("./gr:likingUser", "gr" => GOOGLE_ATOM_NAMESPACE).map do |node| node.text end end |
#original_id ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/google_reader/entry.rb', line 22 def original_id oid_node = id_node.attribute_with_ns("original-id", GOOGLE_ATOM_NAMESPACE) return self.id if oid_node.nil? # Cater to JRuby + libffi return self.id if oid_node.respond_to?(:null?) && oid_node.null? oid_node.text end |
#published_at ⇒ Object
50 51 52 |
# File 'lib/google_reader/entry.rb', line 50 def published_at Time.parse(@entry.search("published").first.text) end |
#source ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/google_reader/entry.rb', line 82 def source node = @entry.search("source").first Source.new(:title => unhtml(node.search("title").first.text), :href => node.search("link[rel=alternate]").first["href"], :id => node.search("id").first.text, :stream_id => node.attribute_with_ns("stream-id", GOOGLE_ATOM_NAMESPACE).text) end |
#summary ⇒ Object
43 44 45 46 47 48 |
# File 'lib/google_reader/entry.rb', line 43 def summary node = @entry.search("summary") return nil unless node return nil if node.respond_to?(:null?) && node.null? node.text end |
#title ⇒ Object
31 32 33 |
# File 'lib/google_reader/entry.rb', line 31 def title unhtml(@entry.search("title").first.text) end |
#unhtml(text) ⇒ Object
103 104 105 |
# File 'lib/google_reader/entry.rb', line 103 def unhtml(text) text.gsub("<", "<").gsub(">", ">").gsub("&", "&").gsub(""", '"') end |
#updated_at ⇒ Object
54 55 56 57 |
# File 'lib/google_reader/entry.rb', line 54 def updated_at node = @entry.search("updated").first node ? Time.parse(@entry.search("updated").first.text) : published_at end |