Class: HackernewsApi::Story

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Story

Returns a new instance of Story.



10
11
12
13
14
15
16
17
18
19
# File 'lib/hackernews_api/story.rb', line 10

def initialize json
  @id     = json['id']
  @by     = json['by']
  @kids   = json['kids']
  @score  = json['score']
  @time   = DateTime.strptime(json['time'].to_s, '%s')
  @title  = json['title']
  @type   = json['type']
  @url    = json['url']
end

Instance Attribute Details

#byObject (readonly)

Returns the value of attribute by.



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

def by
  @by
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#kidsObject (readonly)

Returns the value of attribute kids.



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

def kids
  @kids
end

#scoreObject (readonly)

Returns the value of attribute score.



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

def score
  @score
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.fetch(id) ⇒ Object



3
4
5
6
# File 'lib/hackernews_api/story.rb', line 3

def self.fetch id
  json = Client.fetch(:item, id)
  new(json)
end