Created
July 23, 2015 14:18
-
-
Save dummied/86e7efb1680b1d862ca2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post | |
attr_accessor :id, :title, :body, :summary, :author, :created_at | |
def initialize(hash) | |
@id = hash[:id] | |
@title = hash[:title] | |
@body = hash[:body] | |
@summary = hash[:summary] | |
@author = hash[:author] | |
@created_at = hash[:created_at] || Time.now | |
end | |
def self.all | |
unless defined?(@@posts) | |
@@posts = [ | |
Post.new( | |
:id => 1, | |
:title => "", | |
:body => "FILL_ME_IN", | |
:summary => "FILL_ME_IN", | |
:author => "FILL_ME_IN", | |
:created_at => (1..10).to_a.sample.months.ago | |
), | |
Post.new( | |
:id => 2, | |
:title => "FILL_ME_IN", | |
:body => "FILL_ME_IN", | |
:summary => "FILL_ME_IN", | |
:author => "FILL_ME_IN", | |
:created_at => (1..10).to_a.sample.months.ago | |
), | |
Post.new( | |
:id => 3, | |
:title => "FILL_ME_IN", | |
:body => "FILL_ME_IN", | |
:summary => "FILL_ME_IN", | |
:author => "FILL_ME_IN", | |
:created_at => (1..10).to_a.sample.months.ago | |
), | |
Post.new( | |
:id => 4, | |
:title => "FILL_ME_IN", | |
:body => "FILL_ME_IN", | |
:summary => "FILL_ME_IN", | |
:author => "FILL_ME_IN", | |
:created_at => (1..10).to_a.sample.months.ago | |
), | |
Post.new( | |
:id => 5, | |
:title => "FILL_ME_IN", | |
:body => "FILL_ME_IN", | |
:summary => "FILL_ME_IN", | |
:author => "FILL_ME_IN", | |
:created_at => (1..10).to_a.sample.months.ago | |
) | |
] | |
end | |
@@posts | |
end | |
def self.find(id) | |
all.select{|post| post.id == id} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment