Class: Wikihow::Topic

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_hash = nil, category = nil) ⇒ Topic

Returns a new instance of Topic.



4
5
6
7
8
9
# File 'lib/wikihow/topic.rb', line 4

def initialize(topic_hash = nil, category = nil)
  self.title = topic_hash[:title] if topic_hash != nil
  self.url = topic_hash[:url] if topic_hash != nil
  self.category = category if category != nil
  self.sections = []
end

Instance Attribute Details

#authorObject

TODO



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

def author
  @author
end

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/wikihow/topic.rb', line 3

def category
  @category
end

#introObject

TODO



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

def intro
  @intro
end

#titleObject

TODO



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

def title
  @title
end

#urlObject

TODO



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

def url
  @url
end

Class Method Details

.get_or_create_topics_from_category(category) ⇒ Object



27
28
29
30
31
32
# File 'lib/wikihow/topic.rb', line 27

def self.get_or_create_topics_from_category(category)
  if category.topics == []
    Wikihow::Scraper.scrape_for_topics(category).each{|topic_hash|self.new(topic_hash, category)}
  end
  category.topics
end

Instance Method Details

#sectionsObject



16
17
18
19
20
21
# File 'lib/wikihow/topic.rb', line 16

def sections
  if @sections == []
    @sections = Wikihow::Scraper.scrape_topic(self)
  end
  @sections
end

#sections=(sections) ⇒ Object



23
24
25
# File 'lib/wikihow/topic.rb', line 23

def sections=(sections)
  @sections = sections
end