Class: Socrates::SampleStates::AskForBirthDate

Inherits:
Object
  • Object
show all
Includes:
Core::State
Defined in:
lib/socrates/sample_states.rb

Instance Attribute Summary

Attributes included from Core::State

#adapter, #data, #session, #user

Instance Method Summary collapse

Methods included from Core::State

#end_conversation, #initialize, #next_state_action, #next_state_id, #repeat_action, #respond, #send_message, #transition_to

Instance Method Details

#askObject



98
99
100
# File 'lib/socrates/sample_states.rb', line 98

def ask
  respond message: "Hi #{first_name}! What's your birth date (e.g. MM/DD/YYYY)?"
end

#listen(message) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/socrates/sample_states.rb', line 102

def listen(message)
  begin
    birth_date = Date.strptime(message, "%m/%d/%Y")
  rescue ArgumentError
    respond message: "Whoops, I didn't understand that. What's your birth date (e.g. MM/DD/YYYY)?"
    repeat_action
    return
  end

  transition_to :calculate_age, data: { birth_date: birth_date }
end