Class: Ahub::Question
Instance Attribute Summary collapse
Attributes included from APIResource
#attributes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Deletable
#delete, #undelete
#json_url, #update, #update_attribute
Constructor Details
#initialize(attrs) ⇒ Question
Returns a new instance of Question.
31
32
33
34
|
# File 'lib/ahub/question.rb', line 31
def initialize(attrs)
super
@author = Ahub::User.new(attrs[:author]) if attrs[:author]
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
29
30
31
|
# File 'lib/ahub/question.rb', line 29
def body
@body
end
|
#body_as_html ⇒ Object
Returns the value of attribute body_as_html.
29
30
31
|
# File 'lib/ahub/question.rb', line 29
def body_as_html
@body_as_html
end
|
#title ⇒ Object
Returns the value of attribute title.
29
30
31
|
# File 'lib/ahub/question.rb', line 29
def title
@title
end
|
Class Method Details
.create(title:, body:, topics:, space_id: nil, username:, password:) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/ahub/question.rb', line 6
def self.create(title:, body:, topics:, space_id: nil, username:, password:)
url = "#{base_url}.json"
payload = {title: title, body: body, topics: topics}
payload[:spaceId] = space_id if space_id
= (username:username, password:password)
create_resource(url: url, payload: payload, headers: )
end
|
.find_all_by_text(query:) ⇒ Object
21
22
23
|
# File 'lib/ahub/question.rb', line 21
def self.find_all_by_text(query:)
get_resources(url: "#{base_url}.json?q=#{URI.encode(query.downcase.strip.delete('?'))}", headers: , klass: Ahub::Question)
end
|
.find_by_title(title) ⇒ Object
25
26
27
|
# File 'lib/ahub/question.rb', line 25
def self.find_by_title(title)
find_all_by_text(query: title).find{|question| question.title.strip.downcase == title.downcase.strip}
end
|
.is_question(query:) ⇒ Object
17
18
19
|
# File 'lib/ahub/question.rb', line 17
def self.is_question(query:)
get_resource(url: "#{base_url}/isQuestion.json?q=#{URI.encode(query)}", headers: )[:result]
end
|
Instance Method Details
#fetched_answers ⇒ Object
40
41
42
|
# File 'lib/ahub/question.rb', line 40
def fetched_answers
@fetched_answers || @answers.map{|answer_id| Ahub::Answer.find(answer_id)}
end
|
#find_answers_by_username(username) ⇒ Object
36
37
38
|
# File 'lib/ahub/question.rb', line 36
def find_answers_by_username(username)
fetched_answers.select{|answer| answer.author.username.downcase.strip == username.downcase.strip}
end
|
#html_url ⇒ Object
48
49
50
|
# File 'lib/ahub/question.rb', line 48
def html_url
"#{Ahub::DOMAIN}/questions/#{id}/#{slug}.html" if id
end
|
#to_s ⇒ Object
52
53
54
|
# File 'lib/ahub/question.rb', line 52
def to_s
html_url
end
|
#user ⇒ Object
44
45
46
|
# File 'lib/ahub/question.rb', line 44
def user
@author
end
|