Class: MuseumDay::Museum

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, city = nil, url = nil, hours = nil) ⇒ Museum

Returns a new instance of Museum.



17
18
19
20
21
22
23
# File 'lib/museum_day/museum.rb', line 17

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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def address
  @address
end

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def city
  @city
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def description
  @description
end

#docObject

Returns the value of attribute doc.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def doc
  @doc
end

#fbObject

Returns the value of attribute fb.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def fb
  @fb
end

#hoursObject

Returns the value of attribute hours.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def hours
  @hours
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def name
  @name
end

#phone_numberObject

Returns the value of attribute phone_number.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def phone_number
  @phone_number
end

#twitterObject

Returns the value of attribute twitter.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def twitter
  @twitter
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def url
  @url
end

#website_urlObject

Returns the value of attribute website_url.



3
4
5
# File 'lib/museum_day/museum.rb', line 3

def website_url
  @website_url
end

Class Method Details

.allObject



25
26
27
# File 'lib/museum_day/museum.rb', line 25

def self.all
  @@all
end

.clear_allObject



65
66
67
# File 'lib/museum_day/museum.rb', line 65

def self.clear_all
  @@all.clear
end

.find(id) ⇒ Object



29
30
31
# File 'lib/museum_day/museum.rb', line 29

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

.new_from_index(museum) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/museum_day/museum.rb', line 8

def self.new_from_index(museum)
  self.new(
    museum.css("h4.name").text,
    museum.css("h5.location").text,
    museum.css("a").attribute("href").value,
    museum.at("div strong").next_sibling.text.strip
  )
end

Instance Method Details

#social_urlsObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/museum_day/museum.rb', line 45

def social_urls
  social_links = doc.css("div.contact a").collect { |link| link.attribute("href").value }

  social_links.each do |link|
    if link.include?("twitter")
      self.twitter = link
    elsif link.include?("facebook")
      self.fb = link
    end
  end
end