Class: SE::API::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/se/api/types/post.rb

Direct Known Subclasses

Answer, Question

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_json) ⇒ Post

Returns a new instance of Post.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/se/api/types/post.rb', line 9

def initialize(item_json)
  @json = Hash(item_json)
  @body = @json["body"]
  @title = @json["title"]
  @link = @json["link"]
  @score = @json["score"].to_i
  @type = @json["post_type"]
  @last_editor = User.new(@json["last_editor"])
  @comments = Array(@json["comments"]&.map { |c| Comment.new(c) })
  @id = (@json["post_id"] || @json["answer_id"] || @json["question_id"]).to_i
  @updated_at = @json["last_activity_date"]
  @created_at = @json["creation_date"]
  @author = User.new(@json["owner"])
end

Instance Attribute Details

#authorObject (readonly) Also known as: user, owner

Returns the value of attribute author.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def body
  @body
end

#commentsObject (readonly)

Returns the value of attribute comments.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def comments
  @comments
end

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def id
  @id
end

#jsonObject (readonly)

Returns the value of attribute json.



7
8
9
# File 'lib/se/api/types/post.rb', line 7

def json
  @json
end

#last_editorObject (readonly)

Returns the value of attribute last_editor.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def last_editor
  @last_editor
end

Returns the value of attribute link.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def link
  @link
end

#scoreObject (readonly)

Returns the value of attribute score.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def score
  @score
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def type
  @type
end

#updated_atObject (readonly) Also known as: last_activity_date

Returns the value of attribute updated_at.



6
7
8
# File 'lib/se/api/types/post.rb', line 6

def updated_at
  @updated_at
end