Class: FreeArtExhibits::Exhibit

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, title, description) ⇒ Exhibit

def self.new_from_index_page(exhibit)

self.new(
    "http://www.timeout.com" + exhibit.css("a.read-more").attr("href").value + "#tab_panel_2",
    exhibit.css("h3 a").text,
    exhibit.css("p.feature_item__annotation--truncated").text
    )

end



15
16
17
18
19
20
# File 'lib/free_art_exhibits/exhibit.rb', line 15

def initialize(url, title, description)
   @url = url
   @title = title
   @description = description
   @@all << self
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all
    @@all
end

.find(id) ⇒ Object



26
27
28
# File 'lib/free_art_exhibits/exhibit.rb', line 26

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

Instance Method Details

#addressObject



40
41
42
43
44
45
# File 'lib/free_art_exhibits/exhibit.rb', line 40

def address
    string = "\n"
    self.details_page.css("tr td").select do |cell|
        cell.text + string + cell.css("br").first.text if cell.text.include?("<br>")
    end.first
end

#details_pageObject



47
48
49
# File 'lib/free_art_exhibits/exhibit.rb', line 47

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

#opening_hoursObject



34
35
36
37
38
# File 'lib/free_art_exhibits/exhibit.rb', line 34

def opening_hours
   self.details_page.css("tbody td").select do |cell|
       cell.text if cell.text.include?("pm") || cell.text.include?("am")
   end.first
end

#venue_nameObject



30
31
32
# File 'lib/free_art_exhibits/exhibit.rb', line 30

def venue_name
   self.details_page.css("td a").first.text
end