Class: Route

Inherits:
Object
  • Object
show all
Defined in:
lib/pennride/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, link) ⇒ Route

Returns a new instance of Route.



4
5
6
7
# File 'lib/pennride/route.rb', line 4

def initialize(name, link)
  @name, @link = name, link.gsub('direction', 'stops')
  @id = @link.split("/")[-2]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/pennride/route.rb', line 2

def id
  @id
end

Returns the value of attribute link.



2
3
4
# File 'lib/pennride/route.rb', line 2

def link
  @link
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/pennride/route.rb', line 2

def name
  @name
end

Instance Method Details

#stops(link = @link) ⇒ Object

Returns array of instantiated Stops associated with Route



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pennride/route.rb', line 10

def stops(link = @link)
  @stops = Wombat.crawl {
    base_url ROOT
    path link
    stops "xpath=//li[@class='arrow']/a[contains(@href, '/stops/')]", :iterator do
      name "xpath=./text()"
      href "xpath=./@href"
    end
  }['stops'].map { |s| Stop.new(s['name'], s['href']) } unless @stops
  @stops
end