Class: LocalLibrary::CLI
- Inherits:
-
Object
- Object
- LocalLibrary::CLI
- Defined in:
- lib/local_library/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #choice(zip_code) ⇒ Object
- #details(zip_code) ⇒ Object
- #list(zip_code) ⇒ Object
- #start ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/local_library/cli.rb', line 3 def call puts "" puts "____________________ Welcome to the Local Library Finder ____________________" puts "Please enter a zip code to find the nearest library or 'exit' to exit program." puts "" start end |
#choice(zip_code) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/local_library/cli.rb', line 19 def choice(zip_code) if zip_code.length == 5 && ZIPS.include?(zip_code) list(zip_code) puts "" puts "Please enter the branch number you would like more information on or 'exit' to exit program." elsif zip_code.length == 1 && zip_code.to_i.between?(1, LocalLibrary::Library.libraries.length) details(zip_code) puts "" puts "Please enter another branch nummber, zip code or 'exit' to exit program." elsif zip_code == 'exit' puts "" puts "Thank you for using the Local Library Finder. Keep on learning." else puts "That is not a valid entry, please try again, or type 'exit' to exit program." end end |
#details(zip_code) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/local_library/cli.rb', line 48 def details(zip_code) puts "" puts "...Preparing branch details..." puts "_____________________________________________________________________________" puts "#{LocalLibrary::Library.libraries[zip_code.to_i-1].branch}" puts " #{LocalLibrary::Library.libraries[zip_code.to_i-1].phone}" puts " #{LocalLibrary::Library.libraries[zip_code.to_i-1].address}" puts " #{LocalLibrary::Library.libraries[zip_code.to_i-1].status}" puts "_____________________________________________________________________________" end |
#list(zip_code) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/local_library/cli.rb', line 36 def list(zip_code) LocalLibrary::Library.clear puts "" puts "...Public libraries near #{zip_code}..." library = LocalLibrary::Scraper.scrape_and_create(zip_code) puts "_____________________________________________________________________________" LocalLibrary::Library.libraries.each.with_index(1) do |library, i| puts "#{i}. #{library.branch}" end puts "_____________________________________________________________________________" end |
#start ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/local_library/cli.rb', line 11 def start zip_code = nil while zip_code != 'exit' zip_code = gets.strip choice(zip_code) end end |