class CLI

Attributes

all_breeds_list[RW]

Public Instance Methods

all_breeds() click to toggle source
# File lib/best_friend/cli.rb, line 72
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
    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)
    self.display_info(breed_object)
  end   
end
breeds_by_AKC() click to toggle source
# File lib/best_friend/cli.rb, line 114
def breeds_by_AKC
  self.group_by(Scraper.group_by_AKC)
end
continue() click to toggle source
# File lib/best_friend/cli.rb, line 189
def continue
  more = self.prompt.yes?("Do You want to find other breed?")
  if more
    self.menu
  else
    self.exit
  end
end
create_art(str, fonttype) click to toggle source
# File lib/best_friend/cli.rb, line 145
def create_art(str, fonttype)
  artii = Artii::Base.new :font => fonttype
  artii.asciify(str)
end
display_bio(str) click to toggle source
# File lib/best_friend/cli.rb, line 150
def display_bio(str)
  bio = self.create_art('BIO', 'smslant')
  bio = self.pastel.decorate(bio, :cyan)
  bio_table = Terminal::Table.new :title => bio
  str = self.fit_in_table(str)
  bio_table << [str]
  bio_table.style = {:width => 105}
  bio_table
end
display_charac(array) click to toggle source
# File lib/best_friend/cli.rb, line 160
def display_charac(array)
  c_table = Terminal::Table.new do |t|
    array.each do|c| 
      t.add_row [c.name, self.pastel.bright_yellow('*'* c.stars + self.pastel.white('*'*(5-c.stars)))]
    end
  end
  c_table.style = {:all_separators => true,:alignment => :center}
  title =  self.create_art('Main characteristics', 'smslant')
  title = self.pastel.cyan(title)
  c_table.title = title
  c_table
end
display_info(object) click to toggle source
# File lib/best_friend/cli.rb, line 118
  def display_info(object)
    system 'clear'
    puts self.welcome

    ############### Breed Name ###############
    name = self.display_name(object.name)
    ############### Table for Bio #############
    bio_table = self.display_bio(object.bio)
    ############### Table for characteristic #####################
    c_table = self.display_charac(object.characteristics)
    ############### Table for Vital Stats ##################
    vital_table = self.display_vital(object)
    ############### Final output #####################
    puts <<~Info
    #{name} 
    #{bio_table}
    #{c_table}
    ==========================================================================================================
    #{vital_table}
    Info
    self.continue
  end
display_name(str) click to toggle source
# File lib/best_friend/cli.rb, line 141
def display_name(str)
  name = self.create_art(str, 'slant')
  name = self.pastel.decorate(name, :bright_blue)
end
display_selected(hash) click to toggle source
# File lib/best_friend/cli.rb, line 103
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)
  self.display_info(breed_object)
end
display_vital(object) click to toggle source
# File lib/best_friend/cli.rb, line 173
def display_vital(object)
  row = [[object.stats.dog_breed_group, object.stats.height, object.stats.weight , object.stats.life_span]]
  headings = ['Dog Breed Group:', 'Height:', 'Weight:', 'Life Span']
  vital_table = Terminal::Table.new :headings => headings, :rows => row
  vital_table.style = {:alignment => :center}
  title = self.create_art('Vital Stats', 'smslant')
  title = self.pastel.cyan(title)
  vital_table.title = title
  vital_table
end
doogle(hash) click to toggle source
# File lib/best_friend/cli.rb, line 62
def doogle(hash)
  puts Doogle.new.doogle_logo
  object= Doogle.new.search(hash)
  if object
  self.display_info(object)
  else
    self.exit
  end
end
exit() click to toggle source
# File lib/best_friend/cli.rb, line 198
def exit
  goodbye = self.create_art('Thanks for use Best Friend', 'slant')
  goodbye = self.pastel.decorate(goodbye, :cyan, :bold)
  puts goodbye
  sleep(3)
  system 'clear'
end
fit_in_table(str) click to toggle source
# File lib/best_friend/cli.rb, line 184
def fit_in_table(str)
  new_str= str.chars.each_slice(100).map(&:join)
  new_str.join("\n")
end
group_by(hash) click to toggle source
# File lib/best_friend/cli.rb, line 86
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
      self.doogle(breeds)
    else
     self.display_selected(breeds)
    end
  else
    self.display_selected(breeds)
  end
end
group_by_characteristics() click to toggle source
# File lib/best_friend/cli.rb, line 110
def group_by_characteristics
  self.group_by(Scraper.group_by_Characteristics)
end
menu() click to toggle source
pastel() click to toggle source
# File lib/best_friend/cli.rb, line 4
def pastel
  Pastel.new
end
prompt() click to toggle source
# File lib/best_friend/cli.rb, line 8
def prompt
  TTY::Prompt.new
end
start() click to toggle source
# File lib/best_friend/cli.rb, line 12
def start
  puts self.welcome
  self.all_breeds_list = Scraper.all_breeds
  self.menu
  
end
welcome() click to toggle source
# File lib/best_friend/cli.rb, line 20
  def welcome
    system 'clear'
    a = Artii::Base.new :font => 'colossal'
    logo = a.asciify('Best Friend')
    logo = self.pastel.green(logo)
    a = Artii::Base.new :font => 'digital'
   
    heading = a.asciify('CLI Project for Flatiron School.')
    heading = self.pastel.decorate(heading, :cyan, :bold)
    
    <<~Logo
      #{logo}
      #{heading}
    Logo
   

  end