module Findable::InstanceMethods

Public Instance Methods

search_by_access(input) click to toggle source
# File lib/concerns/Findable.rb, line 55
def search_by_access(input)
    results = PHLCovidTesting::TestingLocation.all.select do |location|
        location.access_type.downcase[input.downcase]
    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)
        get_input_main_options
    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) click to toggle source
# File lib/concerns/Findable.rb, line 25
def search_by_name(input)
    results = PHLCovidTesting::TestingLocation.all.select do |location|
        location.name.downcase[input.downcase]
    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)
        get_input_main_options
    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) click to toggle source
# File lib/concerns/Findable.rb, line 47
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) click to toggle source
# File lib/concerns/Findable.rb, line 3
def search_by_zipcode(input)
    results = PHLCovidTesting::TestingLocation.all.select do |location|
        location.zipcode.to_s == 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)
        get_input_main_options
    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