Class: Topic

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

Constant Summary collapse

@@all =

has many Portals

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Topic

Returns a new instance of Topic.


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

def initialize(name)
  @name = name
  @portals = []
  # add_portal
  @@all << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


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

def name
  @name
end

#portalsObject

Returns the value of attribute portals


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

def portals
  @portals
end

Class Method Details

.allObject


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

def self.all
  @@all
end

.find_or_create_by_name(name) ⇒ Object


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

def self.find_or_create_by_name(name)
  if self.all.detect{|topic| topic.name == name}
    @topic = self.all.detect{|topic| topic.name == name}
  else
    @topic = self.new(name)
  end
  @topic
end

Instance Method Details

#find_random_portal_pageObject


12
13
14
15
16
# File 'lib/topic.rb', line 12

def find_random_portal_page
  find_rand_portal = Scraper.scrape_portals_page(@name).sample
  # create_portal = Portal.find_rand_portal
  # return create_portal
end