class Socrates::SampleStates::CalculateAge
Public Instance Methods
ask()
click to toggle source
# File lib/socrates/sample_states.rb, line 124 def ask respond message: "Got it #{first_name}! So that makes you #{calculate_age} years old." # Example of a :ask => :ask transition. transition_to :end_conversation_1 end
Private Instance Methods
birth_date()
click to toggle source
# File lib/socrates/sample_states.rb, line 137 def birth_date @data.get(:birth_date) end
calculate_age()
click to toggle source
# File lib/socrates/sample_states.rb, line 141 def calculate_age today = Time.current.to_date age = today.year - birth_date.year age -= 1 if today.month < birth_date.month || (today.month == birth_date.month && birth_date.day > today.day) age end
first_name()
click to toggle source
# File lib/socrates/sample_states.rb, line 133 def first_name @data.get(:name).split.first end