lib/best_friend/cli.rb in best_friend-0.1.0 vs lib/best_friend/cli.rb in best_friend-0.1.1

- old
+ new

@@ -1,37 +1,24 @@ class CLI - attr_accessor :all_breeds_list, :group_by_Characteristics, :breeds_by_group - - def initialize - Async do - self.scrap_data - end.wait - end - + attr_accessor :all_breeds_list def pastel Pastel.new end def prompt TTY::Prompt.new end - def scrap_data - self.all_breeds_list = Scraper.all_breeds - # TODO do this in Async way. - # self.group_by_Characteristics = Scraper.group_by_Characteristics - # self.breeds_by_group = Scraper.group_by_AKC - puts 'no finish yet' - end - - def start puts self.welcome + self.all_breeds_list = Scraper.all_breeds self.menu + end + def welcome system 'clear' a = Artii::Base.new :font => 'colossal' logo = a.asciify('Best Friend') logo = self.pastel.green(logo) @@ -63,51 +50,65 @@ when 2 self.group_by_characteristics when 3 self.breeds_by_AKC when 4 - Doogle.new(self.all_breeds_list) + self.doogle(self.all_breeds_list) + when 5 self.exit end end + def doogle(hash) + puts Doogle.new.doogle_logo + object= Doogle.new.search(hash) + if object + self.display_info(object) + else + self.exit + end + end + def all_breeds input = self.prompt.yes?("The list of breed is #{self.all_breeds_list.size} do you no prefer use Doogle.") if input - Doogle.new(self.all_breeds_list) + puts Doogle.new.doogle_logo + object= Doogle.new.search(self.all_breeds_list) + self.display_info(object) else list = self.all_breeds_list url = self.prompt.enum_select("Select a breed", list, per_page: 10) breed_object= Scraper.create_breed(url) - puts self.display_info(breed_object) + self.display_info(breed_object) end - self.continue end def group_by(hash) choices = hash.keys input = self.prompt.enum_select("Select a Group", choices, per_page: 10) puts self.welcome breeds = Scraper.breeds_by_url(hash[input]) #send the link to breeds_by and return a hash if breeds.size > 50 input = self.prompt.yes?("The list of breeds is #{breeds.size} do you rather use Doogle?") if input - Doogle.new(breeds) + self.doogle(breeds) else - selected_breed_url = self.prompt.enum_select("Select a Group", breeds, per_page: 10) + self.display_selected(breeds) end else - selected_breed_url = self.prompt.enum_select("Select a Group", breeds, per_page: 10) - Scraper.create_breed(selected_breed_url) - puts "TODO: format in better way" + self.display_selected(breeds) end + end + + def display_selected(hash) + selected_breed_url = self.prompt.enum_select("Select a Group", hash, per_page: 10) breed_object = Scraper.create_breed(selected_breed_url) - puts self.display_info(breed_object) - self.continue + self.display_info(breed_object) end + def group_by_characteristics self.group_by(Scraper.group_by_Characteristics) end def breeds_by_AKC @@ -125,17 +126,18 @@ ############### Table for characteristic ##################### c_table = self.display_charac(object.characteristics) ############### Table for Vital Stats ################## vital_table = self.display_vital(object) ############### Final output ##################### - <<~Info + puts <<~Info #{name} #{bio_table} #{c_table} ========================================================================================================== #{vital_table} Info + self.continue end def display_name(str) name = self.create_art(str, 'slant') name = self.pastel.decorate(name, :bright_blue) @@ -184,10 +186,9 @@ new_str.join("\n") end def continue more = self.prompt.yes?("Do You want to find other breed?") - if more self.menu else self.exit end \ No newline at end of file