Class: Wikihow::Category

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/wikihow/category.rb', line 2

def title
  @title
end

#topicsObject

Returns the value of attribute topics.



2
3
4
# File 'lib/wikihow/category.rb', line 2

def topics
  @topics
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/wikihow/category.rb', line 2

def url
  @url
end

Class Method Details

.allObject



15
16
17
# File 'lib/wikihow/category.rb', line 15

def self.all
  @@all
end

.get_or_create_categoriesObject



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