class Ahub::Question
Attributes
body[RW]
body_as_html[RW]
title[RW]
Public Class Methods
create(title:, body:, topics:, space_id: nil, username:, password:)
click to toggle source
# 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:)
click to toggle source
# 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)
click to toggle source
# 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:)
click to toggle source
# 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
new(attrs)
click to toggle source
Calls superclass method
Ahub::APIResource::new
# File lib/ahub/question.rb, line 31 def initialize(attrs) super @author = Ahub::User.new(attrs[:author]) if attrs[:author] end
Public Instance Methods
fetched_answers()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/ahub/question.rb, line 48 def html_url "#{Ahub::DOMAIN}/questions/#{id}/#{slug}.html" if id end
to_s()
click to toggle source
# File lib/ahub/question.rb, line 52 def to_s html_url end
user()
click to toggle source
# File lib/ahub/question.rb, line 44 def user @author end