Module: Findable::InstanceMethods
- Included in:
- PHLCovidTesting::CLI, PHLCovidTesting::TestingLocation
- Defined in:
- lib/concerns/Findable.rb
Instance Method Summary collapse
- #search_by_access(input) ⇒ Object
- #search_by_name(input) ⇒ Object
- #search_by_name_or_zipcode(input) ⇒ Object
- #search_by_zipcode(input) ⇒ Object
Instance Method Details
#search_by_access(input) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/concerns/Findable.rb', line 50 def search_by_access(input) results = [] PHLCovidTesting::TestingLocation.all.each.with_index(1) do |x, i| results << x if x.access_type.downcase.include?(input) end if results.length == 0 puts "\nNo match found. Please try again.\n".colorize(:red) get_input_main elsif results.length == 1 puts display_detail(results[0]) puts "\nAll results displayed. Returning to main menu...\n".colorize(:green) else results.each.with_index(1) {|x, i| puts "\n#{i}. #{x.name}"} puts "\nEnter another number to see location details, 'all' to see the full list of locations, 'main' to return to the main menu,\nor 'exit' to end the program.\n".colorize(:yellow) get_input_sub(results) end end |
#search_by_name(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/concerns/Findable.rb', line 22 def search_by_name(input) results = [] PHLCovidTesting::TestingLocation.all.each.with_index(1) do |x, i| results << x if x.name.downcase.include?(input) end if results.length == 0 puts "\nNo match found. Please try again.\n".colorize(:red) get_input_main elsif results.length == 1 puts display_detail(results[0]) puts "\nAll results displayed. Returning to main menu...\n".colorize(:green) else results.each.with_index(1) {|x, i| puts "\n#{i}. #{x.name}"} puts "\nEnter another number to see location details, 'all' to see the full list of locations, 'main' to return to the main menu,\nor 'exit' to end the program.\n".colorize(:yellow) get_input_sub(results) end end |
#search_by_name_or_zipcode(input) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/concerns/Findable.rb', line 42 def search_by_name_or_zipcode(input) if input =~ /\d{5}/ search_by_zipcode(input) else search_by_name(input) end end |
#search_by_zipcode(input) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/concerns/Findable.rb', line 3 def search_by_zipcode(input) results = PHLCovidTesting::TestingLocation.all.map.with_index(1) do |x, i| x if x.zipcode.to_s == input end.compact if results.length == 0 puts "\nNo match found. Please try again.\n".colorize(:red) get_input_main elsif results.length == 1 puts display_detail(results[0]) puts "\nAll results displayed. Returning to main menu...\n".colorize(:green) else results.each.with_index(1) {|x, i| puts "\n#{i}. #{x.name}"} puts "\nEnter another number to see location details, 'all' to see the full list of locations, 'main' to return to the main menu,\nor 'exit' to end the program.\n".colorize(:yellow) get_input_sub(results) end end |