class StellingBanjos::Cli
Constants
- LINK
Public Instance Methods
add_newlines(string, max_length)
click to toggle source
# File lib/stelling_banjos/cli.rb, line 141 def add_newlines(string, max_length) words = string.split(' ') lines = [] current_line = '' until words.empty? current_line += " #{words.shift}" if current_line.length >= max_length lines << current_line current_line = '' end end lines.push(current_line).join("\n ").lstrip end
create_banjos()
click to toggle source
# File lib/stelling_banjos/cli.rb, line 42 def create_banjos StellingBanjos::Scraper.scrape_catalog_page(LINK) StellingBanjos::Banjos.create_from_catalog(StellingBanjos::Scraper.all) end
display_banjos()
click to toggle source
# File lib/stelling_banjos/cli.rb, line 47 def display_banjos puts "" puts " ██████╗ █████╗ ████████╗ █████╗ ██╗ ██████╗ ██████╗ ".colorize(:green) puts " ██╔════╝██╔══██╗╚══██╔══╝██╔══██╗██║ ██╔═══██╗██╔════╝ ".colorize(:green) puts " ██║ ███████║ ██║ ███████║██║ ██║ ██║██║ ███╗".colorize(:green) puts " ██║ ██╔══██║ ██║ ██╔══██║██║ ██║ ██║██║ ██║".colorize(:green) puts " ╚██████╗██║ ██║ ██║ ██║ ██║███████╗╚██████╔╝╚██████╔╝".colorize(:green) puts " ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ".colorize(:green) puts " ███████████████████████████████████████████████████████████".colorize(:green) puts " ~ Supplied by www.elderly.com ~".colorize(:red) puts "" StellingBanjos::Banjos.all.each.with_index do |banjo, index| if banjo.sold_out? puts " #{index + 1}. #{banjo.name} - #{banjo.price}" + " - SOLD OUT".colorize(:red) else puts " #{index + 1}. #{banjo.name} - #{banjo.price}" end end second_menu end
exit_out()
click to toggle source
# File lib/stelling_banjos/cli.rb, line 155 def exit_out puts "" puts " ██████╗ ██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███████╗██╗ ".colorize(:red) puts " ██╔════╝ ██╔═══██╗██╔═══██╗██╔══██╗██╔══██╗╚██╗ ██╔╝██╔════╝██║".colorize(:red) puts " ██║ ███╗██║ ██║██║ ██║██║ ██║██████╔╝ ╚████╔╝ █████╗ ██║".colorize(:red) puts " ██║ ██║██║ ██║██║ ██║██║ ██║██╔══██╗ ╚██╔╝ ██╔══╝ ╚═╝".colorize(:red) puts " ╚██████╔╝╚██████╔╝╚██████╔╝██████╔╝██████╔╝ ██║ ███████╗██╗".colorize(:red) puts " ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ".colorize(:red) puts " ███████████████████████████████████████████████████████████████".colorize(:red) puts "" end
info_page_display(input)
click to toggle source
# File lib/stelling_banjos/cli.rb, line 90 def info_page_display(input) input = input.to_i - 1 link = StellingBanjos::Banjos.all[input].link description = StellingBanjos::Scraper.scrape_info_page(link) formatted_description = add_newlines(description, 68) name = StellingBanjos::Banjos.all[input].name price = StellingBanjos::Banjos.all[input].price puts "" puts "" puts " █ #{name.upcase} - #{price}".colorize(:green) puts "" puts " █ #{formatted_description}" puts "" if StellingBanjos::Banjos.all[input].sold_out? puts " █ SORRY! This banjo is SOLD OUT from elderly.com! Let's check Google instead...".colorize(:red) puts " ==> https://www.google.com/search?q=#{name.downcase.gsub(" ", "-")}".colorize(:blue) else puts " █ Interested in buying? Go here:" puts " ==> #{link}".colorize(:blue) end puts "" third_menu end
start()
click to toggle source
# File lib/stelling_banjos/cli.rb, line 5 def start puts "" puts " ██████╗ █████╗ ███╗ ██╗ ██╗ ██████╗ ███████╗██╗".colorize(:green) puts " ██╔══██╗██╔══██╗████╗ ██║ ██║██╔═══██╗██╔════╝██║".colorize(:green) puts " ██████╔╝███████║██╔██╗ ██║ ██║██║ ██║███████╗██║".colorize(:green) puts " ██╔══██╗██╔══██║██║╚██╗██║██ ██║██║ ██║╚════██║╚═╝".colorize(:green) puts " ██████╔╝██║ ██║██║ ╚████║╚█████╔╝╚██████╔╝███████║██╗".colorize(:green) puts " ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚════╝ ╚═════╝ ╚══════╝╚═╝".colorize(:green) puts " ██████████████████████████████████████████████████████".colorize(:green) puts "" puts " Hello! Welcome to the Stelling Banjos catalog! The best banjos in the world!" first_menu end