Sha256: b43e48d57cf19344ef742a8baf8b45583d2014d2835a3bf413fa71fd5b73b590

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

class VegOut::Scraper

  def self.get_page
    input = gets.strip.to_s
    @doc = Nokogiri::HTML(open("https://www.happycow.net/searchmap?lat=&lng=&location=#{input}&vegan=true&vegetarian=true&vegfriendly=true&distance=20&distanceType=mi&limit=25"))
    self.scrape_results
  end

  def self.create_restaurant(name = nil, address = nil, phone = nil, description = nil)
    VegOut::Restaurant.new(
      @name = @deets.css("h1.header__title").text,
      @address = @deets.css("p.icon__text__desc").text.strip,
      @phone = @deets.css("div.icon__text").children.css("span").first.text,
      @description = @deets.css("div.venue__description.mb--3").children.css("p").text.gsub(/\s+/, " ").strip
      )
      class << self
        attr_accessor :name, :address, :phone, :description
      end
  end

  def self.scrape_results
    @restaurants = @doc.css("h5").map {|name| name.text}.uniq
    @distance = @doc.css("div.grid__group.js-venues").children.css("span.distance").map {|d| d.text}
    class << self
      attr_accessor :restaurants, :distance
    end

      if @restaurants != []
        VegOut::CLI.create_list
      else
        VegOut::CLI.retry
      end
  end

  def self.find_details_page
    info = gets.strip.to_i

      if info > @restaurants.size || info == 0
        puts "Invalid choice. Select a number from the list above:"
        self.find_details_page
      else
        details = @doc.css("div.thumbnail__box a").map {|link| link['href']}.uniq
        @deets = Nokogiri::HTML(open("https://www.happycow.net" << details[info-1].to_s))
        VegOut::CLI.more_details
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
veg_out-0.2.3 lib/veg_out/scraper.rb
veg_out-0.2.2 lib/veg_out/scraper.rb
veg_out-0.2.1 veg_out/lib/veg_out/scraper.rb