class MicroGreens::Scraper

Attributes

description_one[RW]
description_two[RW]
grow_info[RW]
maturity[RW]
name[RW]
new_from_homepage[RW]

Public Class Methods

new(name=nil, new_from_homepage=nil) click to toggle source
# File lib/micro_greens/scraper.rb, line 4
def initialize(name=nil, new_from_homepage=nil)
  @name = name
  @new_from_homepage = new_from_homepage
end

Public Instance Methods

homepage() click to toggle source
# File lib/micro_greens/scraper.rb, line 14
def homepage #main page with all micro-greens
  doc = html.css("div#search-result-items")
  micro_greens_tiles = Array.new
  doc.css("div.o-layout__col").each do |tile|
    name = tile.css("div.c-tile__col a.c-tile__link div.c-tile__name").text
    link = tile.css("a").attribute("href").value.gsub("/vegetables/micro-greens","")
    micro_greens_tiles << {name: name, link: link}
  end
  micro_greens_tiles
end
html() click to toggle source

HOMEPAGE

# File lib/micro_greens/scraper.rb, line 10
def html
  Nokogiri::HTML(open("http://www.johnnyseeds.com/vegetables/micro-greens"))
end
list_greens() click to toggle source
# File lib/micro_greens/scraper.rb, line 25
def list_greens #list of greens in alphabetical order, from homepage
  homepage.sort_by{|hash| hash[:name]}.each.with_index do |hash, index|
     puts "#{index+1}. #{hash[:name].strip}"
  end
end
select(input) click to toggle source
# File lib/micro_greens/scraper.rb, line 31
def select(input)
  homepage.sort_by{|hash| hash[:name]}[input-1]
end