Class: Rzman::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rzman/CLI.rb

Direct Known Subclasses

Scraper, Zmanim

Instance Method Summary collapse

Instance Method Details

#callObject



6
7
8
9
# File 'lib/rzman/CLI.rb', line 6

def call
  puts "Welcome to RZman!".colorize(:light_blue)
  menu
end

#get_shabbat_zmanimObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/rzman/CLI.rb', line 79

def get_shabbat_zmanim
  Rzman::Zmanim.shabbat_time
  puts "Do you want to go back to the main menu? (y/n):".colorize(:light_cyan)
  choice = gets.strip
  if choice == "y"
    menu
  else
    goodbye
  end
end

#get_zmanimObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/rzman/CLI.rb', line 68

def get_zmanim
  Rzman::Zmanim.zmanim_today
  puts "Do you want to go back to the main menu? (y/n):".colorize(:light_cyan)
  choice = gets.strip
  if choice == "y"
    menu
  else
    goodbye
  end
end

#goodbyeObject



90
91
92
93
94
# File 'lib/rzman/CLI.rb', line 90

def goodbye
  puts "Happy davening!".colorize(:light_blue)
  puts "RZman brought to you by Rabbi Ben Greenberg.".colorize(:light_blue)
  exit
end


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rzman/CLI.rb', line 11

def menu
  puts "Please choose from the following:".colorize(:light_blue)
  puts ""
  @first_choice = nil
  puts "1. Get my zmanim for the day"
  puts "2. Get my candle lighting for this Shabbat"
  puts ""
  puts "Please enter '1' or '2' or 'exit'".colorize(:light_cyan)
  @first_choice = gets.strip
  if @first_choice == "1"
    puts "Please enter a valid U.S. zipcode:".colorize(:light_cyan)
    @@zip_input = gets.strip
    if zip_valid? == nil
      puts "Only valid U.S. zipcodes will work (5 digits long).".colorize(:red)
      puts "Do you want to start again? (y/n)".colorize(:light_cyan)
      do_over_choice = gets.strip
      if do_over_choice == "y"
        menu
      else
        goodbye
      end
    else
      get_zmanim
    end
  elsif @first_choice == "2"
    puts "Please enter a valid U.S zipcode:".colorize(:light_cyan)
    @@zip_input = gets.strip
    if zip_valid? == nil
      puts "Only valid U.S. zipcodes will work (5 digits long).".colorize(:red)
      puts "Do you want to start again? (y/n)".colorize(:light_cyan)
      do_over_choice = gets.strip
      if do_over_choice == "y"
        menu
      else
        goodbye
      end
    else
    get_shabbat_zmanim
  end
  elsif @first_choice == "exit"
    goodbye
  else
    return_to_menu
  end
end

#return_to_menuObject



57
58
59
60
61
# File 'lib/rzman/CLI.rb', line 57

def return_to_menu
  @first_choice != "1" || @first_choice != "2" || @first_choice != "exit"
  puts "Please enter a valid option.".colorize(:red)
  menu
end

#zip_valid?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/rzman/CLI.rb', line 63

def zip_valid?
  @@zip_input.to_s
  @@zip_input.match(/^\d{5}$/)
end