pennride 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/lib/pennride.rb +21 -0
- data/lib/pennride/route.rb +21 -0
- data/lib/pennride/stop.rb +19 -0
- data/lib/pennride/version.rb +5 -0
- data/pennride.gemspec +19 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matt Parmett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# pennride: A humble ruby gem hoping to make sense of Penn Transit #
|
2
|
+
|
3
|
+
There are cool new Penn Transit buses, but not a single Penn student **ever** uses them. This must piss *someone* in the administration off, right?
|
4
|
+
|
5
|
+
Well, maybe more students would hop on a bus if they knew:
|
6
|
+
|
7
|
+
* **where** the buses stopped (some routes go to Rittenhouse -- this means free transport to Center City)
|
8
|
+
* **when** the buses are expected to arrive at each stop
|
9
|
+
|
10
|
+
There is an obscure [PennRide website](http://pennrides.com) that has live schedule and map data for buses, but I don't think anybody knows it exists.
|
11
|
+
|
12
|
+
pennride provides you with an easy way to access arrival times by route and stop. Read on to learn how to use the gem.
|
13
|
+
|
14
|
+
## Installation ##
|
15
|
+
|
16
|
+
pennride is hosted on rubygems, so run
|
17
|
+
|
18
|
+
```gem install pennride```
|
19
|
+
|
20
|
+
to install.
|
21
|
+
|
22
|
+
Alternatively, include ```gem 'pennride'``` in your gemfile and run ```bundle install```.
|
23
|
+
|
24
|
+
## How to use pennride ##
|
25
|
+
|
26
|
+
pennride emulates the PennRide bus system through a hierarchy consisting of Routes and Stops.
|
27
|
+
|
28
|
+
### Routes ###
|
29
|
+
|
30
|
+
Routes are individual bus lines within the PennRide system. There are 5 routes:
|
31
|
+
|
32
|
+
* East Shuttle Route
|
33
|
+
* PennBUS East
|
34
|
+
* PennBUS West
|
35
|
+
* West Shuttle Route A
|
36
|
+
* West Shuttle Route B
|
37
|
+
|
38
|
+
Each Route contains several Stops, and Routes may have any number of Stops.
|
39
|
+
|
40
|
+
#### List all Routes ####
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'pennride'
|
44
|
+
pennride = PennRide.new
|
45
|
+
p pennride.routes```
|
46
|
+
|
47
|
+
#### Get all Stops for a certain Route ####
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'pennride'
|
51
|
+
pennride = PennRide.new
|
52
|
+
routes = pennride.routes
|
53
|
+
route = routes.first # East Shuttle Route
|
54
|
+
stops = route.stops```
|
55
|
+
|
56
|
+
### Stops ###
|
57
|
+
|
58
|
+
*Note: Because PennRide is not in operation as of this gem's writing, there is no way for me to test the arrival time function. The gem and docs will be updated when the schedule information becomes available.*
|
59
|
+
|
60
|
+
Stops are, logically, individual bus stops on a given Route. A Stop's `arrival_time` attribute is an array of Strings, each representing the expected arrival time of the next shuttle. For example, `arrival_time[0]` would give you the arrival time of the next bus, `arrival_time[1]` the next, and so on.
|
61
|
+
|
62
|
+
#### Get the arrival times of a Stop ####
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'pennride'
|
66
|
+
pennride = PennRide.new
|
67
|
+
routes = pennride.routes
|
68
|
+
route = routes.first # East Shuttle Route
|
69
|
+
stops = route.stops
|
70
|
+
stop = route.stops.first
|
71
|
+
p stop.arrival_times```
|
72
|
+
|
73
|
+
## Web API ##
|
74
|
+
|
75
|
+
*I plan to make the PennRide information available through a RESTful JSON web API. When the API is available, this section will be updated with the information needed to access the API.*
|
76
|
+
|
77
|
+
## Contributing ##
|
78
|
+
|
79
|
+
If you find any bugs or have feature ideas, feel free to fork and send me a pull request.
|
80
|
+
|
81
|
+
## License ##
|
82
|
+
|
83
|
+
MIT License (see `./LICENSE`), which means you can take this code and do whatever you'd like with it. If you do make use of the source code or the gem, I ask that you do two things:
|
84
|
+
|
85
|
+
1. Give me/this project a hat tip
|
86
|
+
2. Send me the link to your project, so I can feature it on this page
|
data/Rakefile
ADDED
data/lib/pennride.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wombat'
|
2
|
+
Dir[File.dirname(__FILE__) + "/pennride/*.rb"].each { |file| require file }
|
3
|
+
|
4
|
+
ROOT = 'http://pennrides.com'
|
5
|
+
|
6
|
+
class PennRide
|
7
|
+
attr_accessor :routes
|
8
|
+
|
9
|
+
# Returns array of instantiated Routes
|
10
|
+
def initialize(root = ROOT)
|
11
|
+
@root = root
|
12
|
+
@routes = Wombat.crawl {
|
13
|
+
base_url ROOT
|
14
|
+
path '/simple/routes'
|
15
|
+
routes "xpath=//li[@class='arrow']", :iterator do
|
16
|
+
name "xpath=./a/text()"
|
17
|
+
href "xpath=./a/@href"
|
18
|
+
end
|
19
|
+
}['routes'].map { |r| Route.new(r['name'], r['href']) }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Route
|
2
|
+
attr_accessor :id, :link, :name
|
3
|
+
|
4
|
+
def initialize(name, link)
|
5
|
+
@name, @link = name, link.gsub('direction', 'stops')
|
6
|
+
@id = @link.split("/")[-2]
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns array of instantiated Stops associated with Route
|
10
|
+
def stops(link = @link)
|
11
|
+
@stops = Wombat.crawl {
|
12
|
+
base_url ROOT
|
13
|
+
path link
|
14
|
+
stops "xpath=//li[@class='arrow']/a[contains(@href, '/stops/')]", :iterator do
|
15
|
+
name "xpath=./text()"
|
16
|
+
href "xpath=./@href"
|
17
|
+
end
|
18
|
+
}['stops'].map { |s| Stop.new(s['name'], s['href']) } unless @stops
|
19
|
+
@stops
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Stop
|
2
|
+
attr_accessor :arrival_times, :id, :link, :name
|
3
|
+
|
4
|
+
def initialize(name, link)
|
5
|
+
@name, @link = name, link
|
6
|
+
@id = @link.split("/")[-1]
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns array of arrival times (Strings) for the Stop
|
10
|
+
# Note: untested as PennRide isn't operating over winter break
|
11
|
+
def arrival_times(link = @link)
|
12
|
+
@arrival_times = Wombat.crawl {
|
13
|
+
base_url ROOT
|
14
|
+
path link
|
15
|
+
times "xpath=//ul/li[not(contains(@class,'arrow'))]/text()", :list
|
16
|
+
}['times'] unless @arrival_times
|
17
|
+
@arrival_times
|
18
|
+
end
|
19
|
+
end
|
data/pennride.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/pennride/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = "Matt Parmett"
|
6
|
+
gem.email = "mparmett@wharton.upenn.edu"
|
7
|
+
gem.description = %q{Ruby gem to retrieve PennRide schedules}
|
8
|
+
gem.summary = %q{Ruby gem to retrieve PennRide schedules}
|
9
|
+
gem.homepage = "http://github.com/mattparmett/pennride"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "pennride"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PennRide::Ruby::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "wombat"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pennride
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Parmett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: wombat
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Ruby gem to retrieve PennRide schedules
|
31
|
+
email: mparmett@wharton.upenn.edu
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/pennride.rb
|
42
|
+
- lib/pennride/route.rb
|
43
|
+
- lib/pennride/stop.rb
|
44
|
+
- lib/pennride/version.rb
|
45
|
+
- pennride.gemspec
|
46
|
+
homepage: http://github.com/mattparmett/pennride
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.23
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Ruby gem to retrieve PennRide schedules
|
70
|
+
test_files: []
|