Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
| module Players | |
| class Computer < Player | |
| def move(board) | |
| computer_move(board) | |
| end | |
| def computer_move(board) | |
| end |
| def move(board) | |
| #center position | |
| if !board.taken?("5") | |
| "5" | |
| else | |
| computer_move(board) | |
| end | |
| end |
| def computer_move(board) | |
| win_move(board) || block(board) || corner(board) || middle_corner(board) | |
| end |
Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
| def self.scrape_level_two | |
| name = URI.encode(gets.strip) | |
| agent = Mechanize.new | |
| page = agent.get("http://www.packopumps.com/en/products/different-kind-of-pumps/#{name}") | |
| #get each pump series_list | |
| page.search("div.categoryBlock").collect do |ele| | |
| all_series = self.new | |
| all_series.name = ele.text | |
| all_series | |
| end |
| def list_product | |
| PumpSelection::Scraper.scarp | |
| PumpSelection::Scraper.scrape_product | |
| PumpSelection::Scraper.display_product | |
| end | |
| def list_series(input) | |
| PumpSelection::Scraper.scarp | |
| PumpSelection::Scraper.scrape_product | |
| PumpSelection::Scraper.display_series(input) | |
| end |
| def self.display_series(input) | |
| index = input.to_i - 1 | |
| puts "#{@@all[index].series}" | |
| end |
| def self.display_product | |
| @@all.each.with_index(1) do |product, i| | |
| puts " #{i}. #{product.name}" | |
| end | |
| end |
| def self.scrape | |
| @doc = Nokogiri::HTML(open("http://www.packopumps.com/en/products/different-kind-of-pumps")) | |
| @scraping_block = @doc.css("div.listingByBlockContainer div.categoryBlock") | |
| end |
| def self.scrape_product | |
| @scraping_block.each do |ele| | |
| name = ele.css("a.desc").text.strip | |
| series = ele.css("div.sub ul li").text.strip | |
| product = self.new(name, series) | |
| @@all << product | |
| end | |
| end |