Class: HallidayWineList::Category
- Inherits:
-
Object
- Object
- HallidayWineList::Category
- Defined in:
- lib/halliday_wine_list/category.rb
Constant Summary collapse
- @@all_categories =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .all_categories ⇒ Object
- .create_categories ⇒ Object
- .new_from_scraper(name, url) ⇒ Object
- .print_categories ⇒ Object
Instance Method Summary collapse
- #add_wine(wine) ⇒ Object
-
#initialize(name = nil, url = nil) ⇒ Category
constructor
A new instance of Category.
- #print_wines ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/halliday_wine_list/category.rb', line 3 def name @name end |
#url ⇒ Object (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_categories ⇒ Object
7 8 9 |
# File 'lib/halliday_wine_list/category.rb', line 7 def self.all_categories @@all_categories end |
.create_categories ⇒ Object
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 |
.print_categories ⇒ Object
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 |
#print_wines ⇒ Object
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 |