Class: MicroGreens::Scraper
- Inherits:
-
Object
- Object
- MicroGreens::Scraper
- Defined in:
- lib/micro_greens/scraper.rb
Instance Attribute Summary collapse
-
#description_one(input) ⇒ Object
Returns the value of attribute description_one.
-
#description_two(input) ⇒ Object
Returns the value of attribute description_two.
-
#grow_info(input) ⇒ Object
Returns the value of attribute grow_info.
-
#maturity(input) ⇒ Object
Returns the value of attribute maturity.
-
#name(input) ⇒ Object
Returns the value of attribute name.
-
#new_from_homepage(input) ⇒ Object
INDIVIDUAL PROFILE PAGES.
Instance Method Summary collapse
-
#homepage ⇒ Object
main page with all micro-greens.
-
#html ⇒ Object
HOMEPAGE.
-
#initialize(name = nil, new_from_homepage = nil) ⇒ Scraper
constructor
A new instance of Scraper.
-
#list_greens ⇒ Object
list of greens in alphabetical order, from homepage.
- #select(input) ⇒ Object
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
#homepage ⇒ Object
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 |
#html ⇒ Object
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_greens ⇒ Object
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 |