Class: Serel::Answer
Overview
The Answer class represents a Stack Exchange answer object.
Finding answers
There are a few different ways of retrieving answers: all
, get
& find
, as well as the scopes on other classes.
all
Serel::Answer.all
This should probably never be used. all
loads every answer on the site, which, for many sites, involves retrieving lots of pages. However, it’s there. Feel free to use it.
find
Serel::Answer.find(id)
Find an answer by its ID.
get
Serel::Answer.get
Retrieves answers, applying (any) scope that has been set. In reality this won’t be called as given above, rather it will called at the end of a chain of scoping functions, e.g:
Serel::Answer.pagesize(100).sort(:votes).get
which would return the top 100 answers on the site.
Question#answers
Serel::Question.find(id).answers.get
Retrieves the answers on a particular question. The call to answers
returns a Relation object, which accepts all the usual relation scopes. This is true for all of the methods listed below.
User#answers
Serel::User.find(id).answers.get
Retrieves answers by a given user
Instance Method Summary collapse
-
#comments ⇒ Serel::Relation
Get the comments on an answer.
-
#question ⇒ Serel::Question
Get the question this answer answers.
-
#revisions ⇒ Serel::Relation
Get the revisions on an answer.
-
#suggested_edits ⇒ Serel::Relation
Get the suggested edits on an answer.
Methods inherited from Base
#[], #[]=, #all, associations, attribute, config, #find, finder_methods, #get, #initialize, #inspect, #meth, method_missing, #network, network_wide, new_relation, request, respond_to?, #type, with_ids
Constructor Details
This class inherits a constructor from Serel::Base
Instance Method Details
#comments ⇒ Serel::Relation
Get the comments on an answer.
64 65 66 |
# File 'lib/serel/answer.rb', line 64 def comments type(:comment).url("answers/#{id}/comments") end |
#question ⇒ Serel::Question
Get the question this answer answers.
Note that this method returns a question not wrapped in the Response wrapper.
73 74 75 |
# File 'lib/serel/answer.rb', line 73 def question type(:question, :singular).url("questions/#{question_id}").get end |
#revisions ⇒ Serel::Relation
Get the revisions on an answer.
79 80 81 |
# File 'lib/serel/answer.rb', line 79 def revisions type(:revision).url("posts/#{id}/revisions") end |
#suggested_edits ⇒ Serel::Relation
Get the suggested edits on an answer
85 86 87 |
# File 'lib/serel/answer.rb', line 85 def suggested_edits type(:suggested_edit).url("posts/#{id}/suggested-edits") end |