Class: AlexaService

Inherits:
Object
  • Object
show all
Includes:
AlexaConstants
Defined in:
app/services/alexa_service.rb

Overview

Class to define Alexa's intent behavior

Constant Summary

Constants included from AlexaConstants

AlexaConstants::TESTNAME_SLOT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ AlexaService

Returns a new instance of AlexaService.


40
41
42
# File 'app/services/alexa_service.rb', line 40

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user


7
8
9
# File 'app/services/alexa_service.rb', line 7

def user
  @user
end

Class Method Details

.cancel_responseObject


25
26
27
# File 'app/services/alexa_service.rb', line 25

def self.cancel_response
  I18n.t :cancel_response
end

.goodbye_responseObject


9
10
11
# File 'app/services/alexa_service.rb', line 9

def self.goodbye_response
  I18n.t :goodbye_response
end

.help_responseObject


13
14
15
# File 'app/services/alexa_service.rb', line 13

def self.help_response
  I18n.t :help_response
end

.launch_responseObject


17
18
19
# File 'app/services/alexa_service.rb', line 17

def self.launch_response
  I18n.t :launch_response
end

.list_testsObject


29
30
31
# File 'app/services/alexa_service.rb', line 29

def self.list_tests
  format(I18n.t(:list_test_response), count: Instrument.count, list: Instrument.list_tests(limit: 4))
end

.start_over_responseObject


21
22
23
# File 'app/services/alexa_service.rb', line 21

def self.start_over_response
  I18n.t :start_over_response 
end

.start_test(testname: AppConstants::DEFAULT_INSTRUMENT) ⇒ Object


33
34
35
36
37
38
# File 'app/services/alexa_service.rb', line 33

def self.start_test(testname: AppConstants::DEFAULT_INSTRUMENT)
  instrument = Instrument.find_by(name: testname)
  return format(I18n.t(:cannot_find_instrument), instrument: testname) unless instrument
  
  instrument.first_question_and_instructions
end

Instance Method Details

#read_allObject


44
45
46
# File 'app/services/alexa_service.rb', line 44

def read_all
  user.journal.list_entries(limit: 4)
end

#read_entry(day: Date.today) ⇒ Object


48
49
50
# File 'app/services/alexa_service.rb', line 48

def read_entry(day: Date.today)
  user.journal.read_entry(day: day)
end

#read_last(last_n: 1) ⇒ Object


52
53
54
# File 'app/services/alexa_service.rb', line 52

def read_last(last_n: 1)
  user.journal.read_last(last_n: last_n)
end