Class: MicroGreens::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/micro_greens/scraper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, new_from_homepage = nil) ⇒ Scraper



4
5
6
7
# 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

Instance Attribute Details

#description_one(input) ⇒ Object

Returns the value of attribute description_one.



2
3
4
# File 'lib/micro_greens/scraper.rb', line 2

def description_one
  @description_one
end

#description_two(input) ⇒ Object

Returns the value of attribute description_two.



2
3
4
# File 'lib/micro_greens/scraper.rb', line 2

def description_two
  @description_two
end

#grow_info(input) ⇒ Object

Returns the value of attribute grow_info.



2
3
4
# File 'lib/micro_greens/scraper.rb', line 2

def grow_info
  @grow_info
end

#maturity(input) ⇒ Object

Returns the value of attribute maturity.



2
3
4
# File 'lib/micro_greens/scraper.rb', line 2

def maturity
  @maturity
end

#name(input) ⇒ Object

Returns the value of attribute name.



2
3
4
# File 'lib/micro_greens/scraper.rb', line 2

def name
  @name
end

#new_from_homepage(input) ⇒ Object

INDIVIDUAL PROFILE PAGES



40
41
42
# File 'lib/micro_greens/scraper.rb', line 40

def new_from_homepage
  @new_from_homepage
end

Instance Method Details

#homepageObject

main page with all micro-greens



14
15
16
17
18
19
20
21
22
23
# 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

#htmlObject

HOMEPAGE



10
11
12
# File 'lib/micro_greens/scraper.rb', line 10

def html
  Nokogiri::HTML(open("http://www.johnnyseeds.com/vegetables/micro-greens"))
end

#list_greensObject

list of greens in alphabetical order, from homepage



25
26
27
28
29
# 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) ⇒ Object



31
32
33
# File 'lib/micro_greens/scraper.rb', line 31

def select(input)
  homepage.sort_by{|hash| hash[:name]}[input-1]
end