Class: Stars::Post
- Inherits:
-
Object
- Object
- Stars::Post
- Defined in:
- lib/stars/post.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#name ⇒ Object
The String name of the Post.
-
#service ⇒ Object
Returns the value of attribute service.
- #stars ⇒ Object
-
#stars_count ⇒ Object
Returns the value of attribute stars_count.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.filter(posts) ⇒ Object
Filter an Array of Post objects.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Post
constructor
A new instance of Post.
- #more ⇒ Object
-
#short_name ⇒ Object
The shorted String version of ‘name`.
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
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/stars/post.rb', line 6 def date @date end |
#name ⇒ Object
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 |
#service ⇒ Object
Returns the value of attribute service.
4 5 6 |
# File 'lib/stars/post.rb', line 4 def service @service end |
#stars ⇒ Object
40 41 42 |
# File 'lib/stars/post.rb', line 40 def stars @stars end |
#stars_count ⇒ Object
Returns the value of attribute stars_count.
5 6 7 |
# File 'lib/stars/post.rb', line 5 def stars_count @stars_count end |
#url ⇒ Object
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
#more ⇒ Object
44 45 46 |
# File 'lib/stars/post.rb', line 44 def more service.constantize.more(self) end |
#short_name ⇒ Object
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 |