Class: Wikihow::Category
- Inherits:
-
Object
- Object
- Wikihow::Category
- Defined in:
- lib/wikihow/category.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#title ⇒ Object
Returns the value of attribute title.
-
#topics ⇒ Object
Returns the value of attribute topics.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #add_topic(topic) ⇒ Object
-
#initialize(category_hash) ⇒ Category
constructor
A new instance of Category.
Constructor Details
#initialize(category_hash) ⇒ Category
Returns a new instance of Category.
4 5 6 7 8 9 |
# File 'lib/wikihow/category.rb', line 4 def initialize(category_hash) self.title = category_hash[:title] self.url = category_hash[:url] self.topics = [] self.class.all << self end |
Instance Attribute Details
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/wikihow/category.rb', line 2 def title @title end |
#topics ⇒ Object
Returns the value of attribute topics.
2 3 4 |
# File 'lib/wikihow/category.rb', line 2 def topics @topics end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/wikihow/category.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
15 16 17 |
# File 'lib/wikihow/category.rb', line 15 def self.all @@all end |
.get_or_create_categories ⇒ Object
19 20 21 22 23 24 |
# File 'lib/wikihow/category.rb', line 19 def self.get_or_create_categories if self.all == [] Wikihow::Scraper.scrape_for_categories.each{|category| self.new(category)} end self.all end |
Instance Method Details
#add_topic(topic) ⇒ Object
11 12 13 |
# File 'lib/wikihow/category.rb', line 11 def add_topic(topic) self.topics << topic end |