Class: Shark::SharkRays

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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



13
14
15
16
17
# File 'lib/shark/sharkrays.rb', line 13

def initialize(name = nil, url = nil)
    @name = name 
    @url = "https://oceana.org" +url 
    @@all << self 
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def description
  @description
end

#distributionObject

Returns the value of attribute distribution.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def distribution
  @distribution
end

#feedingObject

Returns the value of attribute feeding.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def feeding
  @feeding
end

#habitatObject

Returns the value of attribute habitat.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def habitat
  @habitat
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def name
  @name
end

#scientific_nameObject

Returns the value of attribute scientific_name.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def scientific_name
  @scientific_name
end

#taxonomyObject

Returns the value of attribute taxonomy.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def taxonomy
  @taxonomy
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/shark/sharkrays.rb', line 2

def url
  @url
end

Class Method Details

.allObject



19
20
21
# File 'lib/shark/sharkrays.rb', line 19

def self.all 
    @@all
end

.find(id) ⇒ Object



23
24
25
# File 'lib/shark/sharkrays.rb', line 23

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

.new_from_shark_index(shark) ⇒ Object



6
7
8
9
10
11
# File 'lib/shark/sharkrays.rb', line 6

def self.new_from_shark_index(shark)
    self.new(
        shark.css("h1").text,
        shark.css("a").attr("href").value
    )
end

Instance Method Details

#docObject



27
28
29
# File 'lib/shark/sharkrays.rb', line 27

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