Class: Forrst::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/forrst/comment.rb

Overview

Forrst::Comment is a class used for individual comments.

Author:

  • Yorick Peterse

Since:

  • 0.1a

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Comment

Creates a new instance of Forrst::Comment and parses the response (either in JSON or as a has).

Author:

  • Yorick Peterse

Since:

  • 0.1a

Parameters:

  • The API response sent back from the server.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/forrst/comment.rb', line 57

def initialize(response)
  if response.class != Hash
    response = JSON.load(response)
  end

  @comment_id = response['id']
  @user       = Forrst::User.new(response['user'])
  @body       = response['body']
  @created_at = Date.strptime(response['created_at'], Forrst::DateFormat)
  @updated_at = Date.strptime(response['updated_at'], Forrst::DateFormat)
end

Instance Attribute Details

#bodyObject (readonly)

The body of the comment.

Author:

  • Yorick Peterse

Since:

  • 0.1a



31
32
33
# File 'lib/forrst/comment.rb', line 31

def body
  @body
end

#comment_idObject (readonly)

The ID of the comment.

Author:

  • Yorick Peterse

Since:

  • 0.1a



15
16
17
# File 'lib/forrst/comment.rb', line 15

def comment_id
  @comment_id
end

#created_atObject (readonly)

The date and time on which the comment was created.

Author:

  • Yorick Peterse

Since:

  • 0.1a



39
40
41
# File 'lib/forrst/comment.rb', line 39

def created_at
  @created_at
end

#updated_atObject (readonly)

The date and time on which the comment was updated.

Author:

  • Yorick Peterse

Since:

  • 0.1a



47
48
49
# File 'lib/forrst/comment.rb', line 47

def updated_at
  @updated_at
end

#userObject (readonly)

An instance of Forrst::User containing the details of the user.

Author:

  • Yorick Peterse

Since:

  • 0.1a



23
24
25
# File 'lib/forrst/comment.rb', line 23

def user
  @user
end