Class: TinyHNews::TopStories

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_hnews/top_stories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_of_stories: 10, comments_depth: 2, comments_limit: 20) ⇒ TopStories

Returns a new instance of TopStories.



5
6
7
8
9
10
11
12
13
14
# File 'lib/tiny_hnews/top_stories.rb', line 5

def initialize(
  number_of_stories: 10,
  comments_depth: 2,
  comments_limit: 20
)
  @number_of_stories = number_of_stories
  @comments_depth = comments_depth
  @comments_limit = comments_limit
  @stories = []
end

Instance Attribute Details

#storiesObject (readonly)

Returns the value of attribute stories.



3
4
5
# File 'lib/tiny_hnews/top_stories.rb', line 3

def stories
  @stories
end

Instance Method Details

#fetchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tiny_hnews/top_stories.rb', line 16

def fetch
  top_stories = TinyHNews::API.topstories.first(@number_of_stories)

  @stories =
    top_stories.map do |story_id|
      TinyHNews::Story.new(
        id: story_id,
        comments_depth: @comments_depth,
        comments_limit: @comments_limit
      ).wrap
    end

  self
end