Class: GoogleReader::Entry
- Inherits:
-
Object
- Object
- GoogleReader::Entry
- Defined in:
- lib/google_reader/entry.rb
Instance Attribute Summary collapse
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
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, feed) ⇒ 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, feed) ⇒ Entry
Returns a new instance of Entry.
8 9 10 11 |
# File 'lib/google_reader/entry.rb', line 8 def initialize(entry, feed) @entry = entry @feed = feed end |
Instance Attribute Details
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
6 7 8 |
# File 'lib/google_reader/entry.rb', line 6 def feed @feed end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/google_reader/entry.rb', line 17 def ==(other) self.id == other.id end |
#author ⇒ Object
81 82 83 |
# File 'lib/google_reader/entry.rb', line 81 def @entry.search("author name").first.text end |
#categories ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/google_reader/entry.rb', line 38 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
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/google_reader/entry.rb', line 70 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
13 14 15 |
# File 'lib/google_reader/entry.rb', line 13 def hash self.id.hash end |
#href ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/google_reader/entry.rb', line 62 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
21 22 23 |
# File 'lib/google_reader/entry.rb', line 21 def id id_node.text end |
#id_node ⇒ Object
100 101 102 103 104 |
# File 'lib/google_reader/entry.rb', line 100 def id_node nodes = @entry.search("id") return nil if nodes.empty? nodes.first end |
#liking_users ⇒ Object
93 94 95 96 97 98 |
# File 'lib/google_reader/entry.rb', line 93 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
25 26 27 28 29 30 31 32 |
# File 'lib/google_reader/entry.rb', line 25 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
53 54 55 |
# File 'lib/google_reader/entry.rb', line 53 def published_at Time.parse(@entry.search("published").first.text) end |
#source ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/google_reader/entry.rb', line 85 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
46 47 48 49 50 51 |
# File 'lib/google_reader/entry.rb', line 46 def summary node = @entry.search("summary") return nil unless node return nil if node.respond_to?(:null?) && node.null? node.text end |
#title ⇒ Object
34 35 36 |
# File 'lib/google_reader/entry.rb', line 34 def title unhtml(@entry.search("title").first.text) end |
#unhtml(text) ⇒ Object
106 107 108 |
# File 'lib/google_reader/entry.rb', line 106 def unhtml(text) text.gsub("<", "<").gsub(">", ">").gsub("&", "&").gsub(""", '"') end |
#updated_at ⇒ Object
57 58 59 60 |
# File 'lib/google_reader/entry.rb', line 57 def updated_at node = @entry.search("updated").first node ? Time.parse(@entry.search("updated").first.text) : published_at end |