Test Setup Failed
Push — master ( 0da364...51a441 )
by Steven
01:38
created

AlexaService   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A help_response() 0 3 1
A launch_response() 0 3 1
A goodbye_response() 0 3 1
A start_over_response() 0 3 1
A read_last() 0 3 1
A read_entry() 0 3 1
A start_test() 0 5 2
A list_tests() 0 3 1
A read_all() 0 3 1
A cancel_response() 0 3 1
A initialize() 0 3 1
1
# frozen_string_literal: true
2
3
# Class to define Alexa's intent behavior
4
class AlexaService
5
  include AlexaConstants
6
7
  attr_reader :user
8
9
  def self.goodbye_response
10
    GOODBYE_RESPONSE
11
  end
12
  
13
  def self.help_response
14
    HELP_RESPONSE
15
  end
16
17
  def self.launch_response
18
    LAUNCH_RESPONSE
19
  end
20
  
21
  def self.start_over_response
22
    START_OVER_RESPONSE 
23
  end
24
  
25
  def self.cancel_response
26
    CANCEL_RESPONSE
27
  end
28
29
  def self.list_tests
30
    format(LIST_TEST_RESPONSE, count: Instrument.count, list: Instrument.list_tests(limit: 4))
31
  end
32
33
  def self.start_test(testname: AppConstants::DEFAULT_INSTRUMENT)
34
    instrument = Instrument.find_by(name: testname)
35
    return format(AlexaConstants::CANNOT_FIND_INSTRUMENT_ERROR, instrument: testname) unless instrument
36
    instrument.instructions
37
  end
38
39
  def initialize(user)
40
    @user = user
41
  end
42
43
  def read_all
44
    user.journal.list_entries(limit: 4)
45
  end
46
47
  def read_entry(day: Date.today)
48
    user.journal.read_entry(day: day)
49
  end
50
51
  def read_last(last_n: 1)
52
    user.journal.read_last(last_n: last_n)
53
  end
54
end
55