Class: Snacks::NutsData

Inherits:
Object
  • Object
show all
Defined in:
lib/snacks/nutsdata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = nil, nut_facts = nil) ⇒ NutsData

Returns a new instance of NutsData.



5
6
7
8
# File 'lib/snacks/nutsdata.rb', line 5

def initialize(type=nil, nut_facts=nil)
  @type = type 
  @nut_facts = nut_facts
end

Instance Attribute Details

#nut_factsObject (readonly)

Returns the value of attribute nut_facts.



3
4
5
# File 'lib/snacks/nutsdata.rb', line 3

def nut_facts
  @nut_facts
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/snacks/nutsdata.rb', line 3

def type
  @type
end

Class Method Details

.about_nut_infoObject

> onject <NutsData302405205>.type & facts



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/snacks/nutsdata.rb', line 18

def self.about_nut_info #=> onject <NutsData302405205>.type & facts
  scraper_obj = Snacks::Scraper.new # gives access to all data in Scraper class
  doc = scraper_obj.get_page
  type_aka_header = doc.css("div.plp h1").text
  
  "\nAbout #{type_aka_header}"
  facts = doc.css("div.formatted-content.description p").collect do |p|
    "\n#{p.text}" if !p.text.start_with?("We also")
  end 
  self.new(type_aka_header, facts)
end

.allObject



14
15
16
# File 'lib/snacks/nutsdata.rb', line 14

def self.all
  @@all << self 
end

Instance Method Details

#nutsObject



10
11
12
# File 'lib/snacks/nutsdata.rb', line 10

def nuts
  nuts = ["almonds", "brazilNuts", "cashews", "hazelnuts", "macadamiaNuts", "peanuts","pecans", "pistachios"]
end