Class: GoogleReader::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/google_reader/entry.rb

Instance Method Summary collapse

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

#authorObject



78
79
80
# File 'lib/google_reader/entry.rb', line 78

def author
  @entry.search("author name").first.text
end

#categoriesObject



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

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
# File 'lib/google_reader/entry.rb', line 67

def has_known_author?
  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

#hashObject



10
11
12
# File 'lib/google_reader/entry.rb', line 10

def hash
  self.id.hash
end

#hrefObject



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

#idObject



18
19
20
# File 'lib/google_reader/entry.rb', line 18

def id
  id_node.text
end

#id_nodeObject



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_usersObject



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_idObject



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_atObject



50
51
52
# File 'lib/google_reader/entry.rb', line 50

def published_at
  Time.parse(@entry.search("published").first.text)
end

#sourceObject



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

#summaryObject



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

#titleObject



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("&lt;", "<").gsub("&gt;", ">").gsub("&amp;", "&").gsub("&quot;", '"')
end

#updated_atObject



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