Oh, The Problems You’ll Solve: My First Ruby App

  1. How can I ensure that the user always provides a date in a format that our program can use?
  2. How can I limit a user to only select a date after today?
  3. How can I prevent the user from setting the departure date for after their arrival date?
TTY::Prompt slider in action
prompt = TTY::Prompt.newyear = prompt.slider("Year", min: 2020, max: 2030, step: 1, default: 2020)
today = Time.now
min_year = today.year
min_month = today.month
min_day = today.day
max_month = trip.return_date.month
max_day = trip.return_date.day
max_year = trip.return_date.year
if year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)
if min_month == max_month
month = prompt.slider(“Month”, min: min_month, max: max_month, step: 1)
max_day = max_day_for_month(month, year)
day = prompt.slider(“Day”, min: 1, max: max_day, step: 1)

--

--

github.com/mpottebaum

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store