Class: Stars::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/stars/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Post

Returns a new instance of Post.



15
16
17
18
19
20
21
22
# File 'lib/stars/post.rb', line 15

def initialize(attributes)
  @name        = attributes[:name]
  @url         = attributes[:url]
  @stars       = attributes[:stars]
  @stars_count = attributes[:stars_count]
  @service     = attributes[:service]
  @date        = attributes[:date]
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/stars/post.rb', line 6

def date
  @date
end

#nameObject

The String name of the Post.

This returns the String of the content of the Post (which we just call “name”). We also strip whitespace, since it tends to screw up things on the command line.



29
30
31
# File 'lib/stars/post.rb', line 29

def name
  @name.gsub("\n",' ')
end

#serviceObject

Returns the value of attribute service.



4
5
6
# File 'lib/stars/post.rb', line 4

def service
  @service
end

#starsObject



40
41
42
# File 'lib/stars/post.rb', line 40

def stars
  @stars
end

#stars_countObject

Returns the value of attribute stars_count.



5
6
7
# File 'lib/stars/post.rb', line 5

def stars_count
  @stars_count
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/stars/post.rb', line 3

def url
  @url
end

Class Method Details

.filter(posts) ⇒ Object

Filter an Array of Post objects.

posts - an Array of Post objects to filter

This returns the Array sorted by the 15 most recent stars.



53
54
55
# File 'lib/stars/post.rb', line 53

def self.filter(posts)
  posts.sort{ |a,b| b.date <=> a.date }[0..14]
end

Instance Method Details

#moreObject



44
45
46
# File 'lib/stars/post.rb', line 44

def more
  service.constantize.more(self)
end

#short_nameObject

The shorted String version of ‘name`.

Returns a String of the name truncated at 35 characters.



36
37
38
# File 'lib/stars/post.rb', line 36

def short_name
  name.size > 35 ? "#{name[0..35]}..." : name
end