Class: Rlanyrd::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/rlanyrd/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, url_to_parse = nil) ⇒ Location

Returns a new instance of Location.



7
8
9
10
11
# File 'lib/rlanyrd/location.rb', line 7

def initialize(name, url, url_to_parse = nil)
  @name = name
  @url = url
  @url_to_parse = url_to_parse
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/rlanyrd/location.rb', line 5

def name
  @name
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/rlanyrd/location.rb', line 5

def url
  @url
end

#url_to_parseObject

Returns the value of attribute url_to_parse.



5
6
7
# File 'lib/rlanyrd/location.rb', line 5

def url_to_parse
  @url_to_parse
end

Class Method Details

.allObject



37
38
39
40
# File 'lib/rlanyrd/location.rb', line 37

def self.all
  doc = Nokogiri::HTML(open("http://lanyrd.com/places/"))
  doc.css(".large-country-listing li a").map {|a| self.new(a.text.strip, "http://lanyrd.com" + a[:href]) }
end

Instance Method Details

#conferences(follow_pagination = true) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rlanyrd/location.rb', line 13

def conferences(follow_pagination = true)
  doc = Nokogiri::HTML(open(self.url_to_parse || self.url))
  confs = doc.css(".conference")
  results = confs.inject([]) do |arr, conf|
    name = conf.at_css(".summary.url").text.strip
    url = "http://lanyrd.com" + conf.at_css(".summary.url")[:href]
    city = conf.css(".location a").last.text.strip
    city_url = conf.css(".location a").last[:href]
    date = Date.parse(conf.at_css(".dtstart")[:title])
    tags = conf.css(".tags li a").map {|t| t.text.strip }
    arr << Rlanyrd::Conference.new(name: name, url: url, city: self.class.new(city, city_url), country: self, date: date, tags: tags)
  end
  if follow_pagination
    pagination = doc.css(".pagination li a").last
    if pagination
      2.upto(pagination.text.to_i) do |page|
        results += Rlanyrd::Location.new(self.name, self.url, self.url + "?page=#{page}").conferences(false)
      end
    end
  end
  results
end