uk_buses 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97081644e0b9c221838ea068484d1fe33d5736a4
4
+ data.tar.gz: 0ba3145c6a222a1258373bc0279a74ca507ec450
5
+ SHA512:
6
+ metadata.gz: f5aac4ed93152db29294bbdabffa12016970f023dac3e5f4bd9636180010bac23d44074dfeb1c8b1a026120687dd9c4525d6b2d5fa508d567a4d3fcde832866f
7
+ data.tar.gz: eb3173eba665b849245660fa367da88ad003d799eb0cafca2260037b2fa453c611b37b2b967bff3141c44a1b57fa886ce840dd8fc01f4f4af54e3ecc71ee544e
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uk_buses.gemspec
4
+ gemspec
5
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Max Woolf
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,49 @@
1
+ # UKBuses
2
+
3
+ Grab *real-time* bus information across the entire United Kingdom.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'uk_buses'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install uk_buses
18
+
19
+ ## Usage
20
+
21
+ Using UKBuses couldn't be simpler.
22
+
23
+ Firstly, require it at the top of your file:
24
+
25
+ require 'uk_buses'
26
+
27
+ Create a `Query` object containing the bus stop code. This is normally the code written on bus stops that you text to a number to get real-time updates. They usually begin with a 2 letter code that represents your area, `cd` for Cardiff, `bn` for Brighton & Hove etc.
28
+
29
+ q = UkBuses::Query.new('cdijtgm')
30
+
31
+ Then execute the query to scrape the data:
32
+ **This can take a little while!**
33
+
34
+ results = q.run
35
+
36
+ `run` will return an array of `UkBuses::Bus` objects.
37
+
38
+ That's it!
39
+
40
+
41
+ This is a 0.0.1 release currently so Pull Requests are greatfully received.
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ module UkBuses
2
+ class Bus
3
+
4
+ attr_accessor :route_number, :destination, :arrives
5
+
6
+ def initialize(route_number = nil, destination = nil, arrives = nil)
7
+ @route_number = route_number
8
+ @destination = destination
9
+ @arrives = arrives
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module UkBuses
5
+ class Query
6
+
7
+ def initialize(stop_code)
8
+ fetch_buses(stop_code)
9
+ end
10
+
11
+ def fetch_buses(stop_code)
12
+ buses = []
13
+ doc = Nokogiri::HTML(open("http://nextbuses.mobi/WebView/BusStopSearch/BusStopSearchResults/#{ stop_code }"))
14
+
15
+ doc.xpath('//*[@id="wrapper"]/div[4]/table[1]/tr').each do |row|
16
+ current_bus = {}
17
+ row.children.each do |child|
18
+
19
+ child_inner = child.inner_text.strip
20
+ current_bus[:route_number] = child_inner if child_inner.length >= 1 && child_inner.length < 5
21
+ current_bus[:destination] = child_inner.split(/\b(at|in|DUE)\b/).first[0..-2] if child_inner.length > 5
22
+ if child_inner.split(/\b(at|in|DUE)\b/)[1] == 'DUE'
23
+ current_bus[:arrives] = 'DUE'
24
+ else
25
+ current_bus[:arrives] = child_inner.split(/\b(at|in|DUE)\b/)[2].strip if child_inner.length > 5
26
+ end
27
+ end
28
+ buses << UkBuses::Bus.new(current_bus[:route_number],
29
+ current_bus[:destination],
30
+ current_bus[:arrives])
31
+ end
32
+ buses
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module UkBuses
2
+ VERSION = "0.0.1"
3
+ end
data/lib/uk_buses.rb ADDED
@@ -0,0 +1,8 @@
1
+ Dir[File.dirname(__FILE__) + '/uk_buses/*.rb'].each do |file|
2
+ require file
3
+ puts file.inspect
4
+ end
5
+
6
+ module UkBuses
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'uk_buses' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
data/uk_buses.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uk_buses/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uk_buses"
8
+ spec.version = UkBuses::VERSION
9
+ spec.authors = ["Max Woolf"]
10
+ spec.email = ["maximus@zingysaturn.co.uk"]
11
+ spec.description = %q{Web scraper for all UK bus data}
12
+ spec.summary = %q{ Grab real-time bus info for all UK buses using a groovy Ruby DSL }
13
+ spec.homepage = "http://maxehmookau.github.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "nokogiri"
24
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uk_buses
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Woolf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Web scraper for all UK bus data
56
+ email:
57
+ - maximus@zingysaturn.co.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .DS_Store
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/.DS_Store
69
+ - lib/uk_buses.rb
70
+ - lib/uk_buses/bus.rb
71
+ - lib/uk_buses/query.rb
72
+ - lib/uk_buses/version.rb
73
+ - spec/spec_helper.rb
74
+ - uk_buses.gemspec
75
+ homepage: http://maxehmookau.github.io
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Grab real-time bus info for all UK buses using a groovy Ruby DSL
99
+ test_files:
100
+ - spec/spec_helper.rb