Class: Quby::Answers::API

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/answers/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(answer_repo:) ⇒ API

Returns a new instance of API.



6
7
8
# File 'lib/quby/answers/api.rb', line 6

def initialize(answer_repo:)
  @repo = answer_repo
end

Instance Method Details

#all(questionnaire_key) ⇒ Object



18
19
20
# File 'lib/quby/answers/api.rb', line 18

def all(questionnaire_key)
  @repo.all questionnaire_key
end

#create!(questionnaire_key, attributes = {}) ⇒ Object



22
23
24
25
26
# File 'lib/quby/answers/api.rb', line 22

def create!(questionnaire_key, attributes = {})
  questionnaire = Quby.questionnaires.find(questionnaire_key)
  answer = Services::BuildAnswer.new(questionnaire, attributes).build
  @repo.create! answer
end

#find(questionnaire_key, answer_id, **options) ⇒ Object



10
11
12
# File 'lib/quby/answers/api.rb', line 10

def find(questionnaire_key, answer_id, **options)
  @repo.find questionnaire_key, answer_id, **options
end

#generate_outcome(answer) ⇒ Object



32
33
34
# File 'lib/quby/answers/api.rb', line 32

def generate_outcome(answer)
  Services::OutcomeCalculation.new(answer).calculate
end

#regenerate_outcome!(answer) ⇒ Object



36
37
38
# File 'lib/quby/answers/api.rb', line 36

def regenerate_outcome!(answer)
  Services::OutcomeCalculation.new(answer).update_scores
end

#reload(answer) ⇒ Object



14
15
16
# File 'lib/quby/answers/api.rb', line 14

def reload(answer)
  @repo.reload answer
end

#update!(answer) ⇒ Object



28
29
30
# File 'lib/quby/answers/api.rb', line 28

def update!(answer)
  @repo.update! answer
end