Class: UrbanNews::Story

Inherits:
Object
  • Object
show all
Defined in:
lib/urban_news/story.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, summary, credit, url, content) ⇒ Story

Returns a new instance of Story.



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

def initialize(title, summary, credit, url, content)
  @title = title
  @summary = summary
  @credit = credit
  @url = url
  @content = content
  @@all << self
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/urban_news/story.rb', line 8

def content
  @content
end

#creditObject

Returns the value of attribute credit.



8
9
10
# File 'lib/urban_news/story.rb', line 8

def credit
  @credit
end

#summaryObject

Returns the value of attribute summary.



8
9
10
# File 'lib/urban_news/story.rb', line 8

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/urban_news/story.rb', line 8

def title
  @title
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/urban_news/story.rb', line 8

def url
  @url
end

Class Method Details

.allObject



24
25
26
# File 'lib/urban_news/story.rb', line 24

def self.all
  @@all
end

.find(id) ⇒ Object



28
29
30
# File 'lib/urban_news/story.rb', line 28

def self.find(id)
  self.all[id-1]
end

.latest_postsObject



32
33
34
35
36
37
38
39
40
# File 'lib/urban_news/story.rb', line 32

def self.latest_posts
  self.all.each do |story|
    puts "#{story.title}"
    puts "#{story.summary}"
    puts "#{story.credit}"
    puts "#{story.url}"
    puts "#{story.content}"
  end
end

.new_from_blog_page(s) ⇒ Object



11
12
13
# File 'lib/urban_news/story.rb', line 11

def self.new_from_blog_page(s)
  self.new(s[:title], s[:summary], s[:credit], s[:url], s[:content])
end