Class: SeattleEvents::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/seattle_events/events.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Events

Returns a new instance of Events.



5
6
7
8
9
10
11
# File 'lib/seattle_events/events.rb', line 5

def initialize(attributes = {})
  @date = attributes[:date]
  @name = attributes[:name]
  @time = attributes[:time]
  @location = attributes[:location]
  @rsvp_url = attributes[:rsvp_url]
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/seattle_events/events.rb', line 3

def date
  @date
end

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/seattle_events/events.rb', line 3

def location
  @location
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/seattle_events/events.rb', line 3

def name
  @name
end

#rsvp_urlObject

Returns the value of attribute rsvp_url.



3
4
5
# File 'lib/seattle_events/events.rb', line 3

def rsvp_url
  @rsvp_url
end

#timeObject

Returns the value of attribute time.



3
4
5
# File 'lib/seattle_events/events.rb', line 3

def time
  @time
end

Class Method Details

.allObject



13
14
15
# File 'lib/seattle_events/events.rb', line 13

def self.all
  @@all ||= scrape_meetups
end

.scrape_meetupsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/seattle_events/events.rb', line 17

def self.scrape_meetups
  doc = Nokogiri::HTML(open("https://www.meetup.com/Learn-Code-Seattle/"))
  list_doc = doc.search("div#events-list-module li.line.event-item").to_a
  list_doc.collect.with_index do |event, i|
    name = doc.search("h3.flush--bottom a")[i].text unless doc.search("h3.flush--bottom a")[i] == nil
    self.new({
      date: doc.search(".date")[i].text,
      name: name,
      time: doc.search("span.time")[i].text,
      location: doc.search("dt.event-venuename")[i].text.gsub(/[\n\t]/,""),
      rsvp_url: doc.search("li.rsvp-callout-outer a")[i].attr("href")
    })
  end
end