Class: StrangerThingsDirectory::Locations

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil) ⇒ Locations

Returns a new instance of Locations.



11
12
13
14
15
# File 'lib/stranger_things_directory/locations.rb', line 11

def initialize(name=nil, url=nil)
    @name = name
    @url = url
    @@all << self 
end

Instance Attribute Details

#areaObject

Returns the value of attribute area.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def area
  @area
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def description
  @description
end

#inhabitantsObject

Returns the value of attribute inhabitants.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def inhabitants
  @inhabitants
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def name
  @name
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def type
  @type
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/stranger_things_directory/locations.rb', line 2

def url
  @url
end

Class Method Details

.allObject



26
27
28
# File 'lib/stranger_things_directory/locations.rb', line 26

def self.all 
    @@all 
end

.find(id) ⇒ Object



30
31
32
# File 'lib/stranger_things_directory/locations.rb', line 30

def self.find(id)
    self.all[id-1]
end

.new_location(location) ⇒ Object



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

def self.new_location(location)
    self.new(
        location.css("a figure figcaption.category-page__trending-page-title").text, 
        "https://strangerthings.fandom.com#{location.css("a").attribute("href").text}"
    )
end

Instance Method Details

#docObject



17
18
19
# File 'lib/stranger_things_directory/locations.rb', line 17

def doc
    @doc ||= Nokogiri::HTML(open(self.url))
end