Class: NYCLI::Scraper
- Inherits:
-
Object
- Object
- NYCLI::Scraper
- Defined in:
- lib/nycli/scraper.rb
Constant Summary collapse
- @@page =
1
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .dates ⇒ Object
-
.more ⇒ Object
Scraping next events list:.
- .page ⇒ Object
Instance Method Summary collapse
-
#get_events ⇒ Object
Data structuring helper:.
- #get_page ⇒ Object
-
#initialize(url = "https://www.nyc.com/events/?int4=5") ⇒ Scraper
constructor
A new instance of Scraper.
-
#show_events ⇒ Object
Scraping elements:.
Constructor Details
#initialize(url = "https://www.nyc.com/events/?int4=5") ⇒ Scraper
Returns a new instance of Scraper.
9 10 11 |
# File 'lib/nycli/scraper.rb', line 9 def initialize(url = "https://www.nyc.com/events/?int4=5") @url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/nycli/scraper.rb', line 5 def url @url end |
Class Method Details
.dates ⇒ Object
41 42 43 44 |
# File 'lib/nycli/scraper.rb', line 41 def self.dates counter = 1 dates = self.all.collect { |event| event.date } end |
.more ⇒ Object
Scraping next events list:
48 49 50 51 52 |
# File 'lib/nycli/scraper.rb', line 48 def self.more @@page += 1 NYCLI::Scraper.new("https://www.nyc.com/events/?int4=5&p=" + "#{self.page}").show_events NYCLI::CLI.more_names end |
.page ⇒ Object
37 38 39 |
# File 'lib/nycli/scraper.rb', line 37 def self.page @@page end |
Instance Method Details
#get_events ⇒ Object
Data structuring helper:
19 20 21 |
# File 'lib/nycli/scraper.rb', line 19 def get_events self.get_page.css(".eventrecords li[itemtype='http://schema.org/Event']") end |
#get_page ⇒ Object
13 14 15 |
# File 'lib/nycli/scraper.rb', line 13 def get_page Nokogiri::HTML(URI.open(self.url)) end |
#show_events ⇒ Object
Scraping elements:
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nycli/scraper.rb', line 25 def show_events self.get_events.each do |item| event = NYCLI::CLI.new event.name = item.css("h3").text.strip event.date = item.css(".desktop-date").text.gsub("\n ", " ").strip event.time = item.css(".datevenue strong.nyc-mobile-hidden").text event.description = item.css("p[itemprop='description']").text.gsub("read more", "").strip event.venue = item.css("span[itemprop='name']").text event.link = "https://www.nyc.com" + item.css("a.venuelink").attr("href").text if item.css("a.venuelink").attr("href") end end |