Class: GoogleReader::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#feedObject (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

#authorObject



81
82
83
# File 'lib/google_reader/entry.rb', line 81

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

#categoriesObject



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

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
# File 'lib/google_reader/entry.rb', line 70

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



13
14
15
# File 'lib/google_reader/entry.rb', line 13

def hash
  self.id.hash
end

#hrefObject



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

#idObject



21
22
23
# File 'lib/google_reader/entry.rb', line 21

def id
  id_node.text
end

#id_nodeObject



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_usersObject



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_idObject



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_atObject



53
54
55
# File 'lib/google_reader/entry.rb', line 53

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

#sourceObject



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

#summaryObject



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

#titleObject



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

#updated_atObject



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