Class: Snacks::NutsData
- Inherits:
-
Object
- Object
- Snacks::NutsData
- Defined in:
- lib/snacks/nutsdata.rb
Instance Attribute Summary collapse
-
#nut_facts ⇒ Object
readonly
Returns the value of attribute nut_facts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.about_nut_info ⇒ Object
> onject <NutsData302405205>.type & facts.
- .all ⇒ Object
Instance Method Summary collapse
-
#initialize(type = nil, nut_facts = nil) ⇒ NutsData
constructor
A new instance of NutsData.
- #nuts ⇒ Object
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_facts ⇒ Object (readonly)
Returns the value of attribute nut_facts.
3 4 5 |
# File 'lib/snacks/nutsdata.rb', line 3 def nut_facts @nut_facts end |
#type ⇒ Object (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_info ⇒ Object
> 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 |
.all ⇒ Object
14 15 16 |
# File 'lib/snacks/nutsdata.rb', line 14 def self.all @@all << self end |
Instance Method Details
#nuts ⇒ Object
10 11 12 |
# File 'lib/snacks/nutsdata.rb', line 10 def nuts nuts = ["almonds", "brazilNuts", "cashews", "hazelnuts", "macadamiaNuts", "peanuts","pecans", "pistachios"] end |