Class: Ahub::Question
- Inherits:
-
Object
- Object
- Ahub::Question
- Includes:
- APIResource, Deletable
- Defined in:
- lib/ahub/question.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#body_as_html ⇒ Object
Returns the value of attribute body_as_html.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes included from APIResource
Class Method Summary collapse
- .create(title:, body:, topics:, space_id: nil, username:, password:) ⇒ Object
- .find_all_by_text(query:) ⇒ Object
- .find_by_title(title) ⇒ Object
- .is_question(query:) ⇒ Object
Instance Method Summary collapse
- #fetched_answers ⇒ Object
- #find_answers_by_username(username) ⇒ Object
- #html_url ⇒ Object
-
#initialize(attrs) ⇒ Question
constructor
A new instance of Question.
- #json_url ⇒ Object
- #to_s ⇒ Object
- #user ⇒ Object
Methods included from Deletable
Methods included from APIResource
Constructor Details
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 user_headers = headers(username:username, password:password) create_resource(url: url, payload: payload, headers: user_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: admin_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: admin_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..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 |
#json_url ⇒ Object
52 53 54 |
# File 'lib/ahub/question.rb', line 52 def json_url "#{self.class.base_url}/#{id}.json" if id end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/ahub/question.rb', line 56 def to_s html_url end |
#user ⇒ Object
44 45 46 |
# File 'lib/ahub/question.rb', line 44 def user @author end |