Created
October 11, 2016 17:18
-
-
Save anonymous/8ad2800468e807b61af4b34356bdb7b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative 'scrapper' | |
| require_relative 'logic' | |
| WISHLIST = [ | |
| { name: "Xbox", checked: false }, | |
| { name: "Chien", checked: false } | |
| ] | |
| puts "Bonjour bienvenue sur WISHLIST Master 3000" | |
| loop do | |
| puts "Que voulez vous faire ? [add|search|list|delete|mark|exit]" | |
| answer = gets.chomp | |
| case answer | |
| when "add" | |
| add_item | |
| when "search" | |
| search_inspiration | |
| when "list" | |
| list_items(WISHLIST) | |
| when "delete" | |
| delete_item | |
| when "mark" | |
| mark_item | |
| when "exit" | |
| puts "A + Merci d'avoir utilisé le service" | |
| break | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def list_items(list) | |
| puts "Voici la liste des produits" | |
| list.each_with_index do |item, index| | |
| if item[:checked] | |
| puts "[x] #{index + 1} - #{item[:name]}" | |
| else | |
| puts "[ ] #{index + 1} - #{item[:name]}" | |
| end | |
| end | |
| end | |
| def ask_for_name | |
| puts "Quel produit voulez-vous ajouter ?" | |
| gets.chomp | |
| end | |
| def add_item | |
| list_items(WISHLIST) | |
| valeur = ask_for_name | |
| WISHLIST << { name: valeur, checked: false } | |
| end | |
| def search_inspiration | |
| puts "Que voulez-vous rechercher sur Etsy.com?" | |
| product = gets.chomp | |
| array = scrap_etsy(product) | |
| list_items(array) | |
| puts "Lequel voulez-vous ajouter ? " | |
| number = gets.chomp.to_i | |
| WISHLIST << array[number - 1] | |
| end | |
| def delete_item | |
| list_items(WISHLIST) | |
| puts "Quel produit voulez-vous supprimer ?" | |
| number = gets.chomp.to_i | |
| WISHLIST.delete_at(number - 1) | |
| end | |
| def mark_item | |
| list_items(WISHLIST) | |
| puts "Quel produit voulez-vous marquer ?" | |
| number = gets.chomp.to_i | |
| WISHLIST[number - 1][:checked] = true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| require 'nokogiri' | |
| def scrap_etsy(product) | |
| produit = product | |
| url = "https://www.etsy.com/search?q=#{produit}" | |
| html_file = open(url) | |
| html_doc = Nokogiri::HTML(html_file) | |
| results = [] | |
| html_doc.search('.card-title').each do |element| | |
| results << { name: element.text.strip[0..30], checked: false } | |
| end | |
| return results | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment