Class: HallidayWineList::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/halliday_wine_list/category.rb

Constant Summary collapse

@@all_categories =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil) ⇒ Category

Returns a new instance of Category.



15
16
17
18
19
20
# File 'lib/halliday_wine_list/category.rb', line 15

def initialize(name= nil, url= nil)
  @wines = []
  @name = name
  @url = url
  @@all_categories << self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/halliday_wine_list/category.rb', line 3

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/halliday_wine_list/category.rb', line 3

def url
  @url
end

Class Method Details

.all_categoriesObject



7
8
9
# File 'lib/halliday_wine_list/category.rb', line 7

def self.all_categories
  @@all_categories
end

.create_categoriesObject



26
27
28
# File 'lib/halliday_wine_list/category.rb', line 26

def self.create_categories
  HallidayWineList::Scraper.new.scrape_categories
end

.new_from_scraper(name, url) ⇒ Object



22
23
24
# File 'lib/halliday_wine_list/category.rb', line 22

def self.new_from_scraper(name, url)
  self.new(name, url)
end


11
12
13
# File 'lib/halliday_wine_list/category.rb', line 11

def self.print_categories
  @@all_categories.each.with_index(1) {|c, i| puts "#{i} - #{c.name}"}
end

Instance Method Details

#add_wine(wine) ⇒ Object



30
31
32
# File 'lib/halliday_wine_list/category.rb', line 30

def add_wine(wine)
  @wines << wine
end


34
35
36
# File 'lib/halliday_wine_list/category.rb', line 34

def print_wines
  @wines.each.with_index(1) {|w, i| puts "#{i} #{w.winery} - #{w.variety} - #{w.location}."}
end