Class: Greedy::Entry

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

Defined Under Namespace

Modules: States

Constant Summary collapse

DEFAULT_CHAR_COUNT =
2000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, stream = nil) ⇒ Entry

Instantiate and normalize a new Google Reader entry



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/greedy/entry.rb', line 25

def initialize(item, stream = nil)
  @stream = stream
  @feed = Greedy::Feed.new(item['origin'])
  
  @author = normalize item['author']  
  @google_item_id = item['id']
  @published = item['published']
  @updated = item['updated']
  
  set_body!(item)
  set_title!(item)
  set_href!(item)
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def body
  @body
end

#categoriesObject (readonly)

Returns the value of attribute categories.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def categories
  @categories
end

#feedObject (readonly)

Returns the value of attribute feed.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def feed
  @feed
end

#google_item_idObject (readonly)

Returns the value of attribute google_item_id.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def google_item_id
  @google_item_id
end

#hrefObject (readonly)

Returns the value of attribute href.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def href
  @href
end

#streamObject (readonly)

Returns the value of attribute stream.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def stream
  @stream
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def title
  @title
end

#truncated_bodyObject (readonly)

Returns the value of attribute truncated_body.



3
4
5
# File 'lib/greedy/entry.rb', line 3

def truncated_body
  @truncated_body
end

Instance Method Details

#mark_as_read!Object



54
55
56
# File 'lib/greedy/entry.rb', line 54

def mark_as_read!
  stream.change_state_for(self, States::READ)
end

#published_atObject

Provide the canonical publish date in Time format



45
46
47
# File 'lib/greedy/entry.rb', line 45

def published_at
  Time.at @published rescue nil
end

#share!Object



58
59
60
# File 'lib/greedy/entry.rb', line 58

def share!
  stream.change_state_for(self, States::BROADCAST)
end

#sort_by_timeObject

Provide the entry time by which the entry should be sorted amongst other entries



40
41
42
# File 'lib/greedy/entry.rb', line 40

def sort_by_time
  (updated_at || published_at)
end

#updated_atObject

Provide the canonical date and time of update in Time format



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

def updated_at
  Time.at @updated rescue nil
end