Class: Trendster::Scraper

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.



5
6
7
# File 'lib/trendster/scraper.rb', line 5

def audience
  @audience
end

#dateObject

Returns the value of attribute date.



5
6
7
# File 'lib/trendster/scraper.rb', line 5

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/trendster/scraper.rb', line 5

def description
  @description
end

#locationObject

Returns the value of attribute location.



5
6
7
# File 'lib/trendster/scraper.rb', line 5

def location
  @location
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/trendster/scraper.rb', line 5

def name
  @name
end

Class Method Details

.allObject



7
8
9
# File 'lib/trendster/scraper.rb', line 7

def self.all
  @@all
end

.scrape_library_pageObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trendster/scraper.rb', line 11

def self.scrape_library_page
  all_array = []
  index_url = "http://cuyahogalibrary.org/Events/Event-Results.aspx"
  index_doc = Nokogiri::HTML(open(index_url))
    index_doc.css("article.sixcol").each do |event|
      event_url = "http://cuyahogalibrary.org" + event.css("a")[0]['href'] 
      event_doc = Nokogiri::HTML(open(event_url))
      all_array << {
        name: event_doc.css("h3").text,
        description: event_doc.css("p.one-large-content").text || "",
        date: event_doc.css("strong").text,
        location: event_doc.css("p").css("a").text,
        audience: event_doc.css("p").text.match("Adults") || event_doc.css("p").text.match("Children") || event_doc.css("p").text.match("Families") || event_doc.css("p").text.match("Teens") || event_doc.css("p").text.match("All") || event_doc.css("p").text.match("Preschool") 
      }
  end
  all_array
end