ldbws 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.envrc +1 -0
- data/.gitignore +8 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +79 -0
- data/LICENSE +21 -0
- data/Makefile +8 -0
- data/README.md +47 -0
- data/doc/LICENSE.html +93 -0
- data/doc/Ldbws/Request/GetDeparturesBoard.html +114 -0
- data/doc/Ldbws/Request/GetDeparturesBoardWithDetails.html +116 -0
- data/doc/Ldbws/Request/GetServiceDetails.html +105 -0
- data/doc/Ldbws/Request/GetStationBoard.html +120 -0
- data/doc/Ldbws/Request/GetStationBoardWithDetails.html +120 -0
- data/doc/Ldbws/Request.html +91 -0
- data/doc/Ldbws/ResponseTypes/BaseStationBoard.html +108 -0
- data/doc/Ldbws/ResponseTypes/CallingPoint.html +129 -0
- data/doc/Ldbws/ResponseTypes/Coach.html +114 -0
- data/doc/Ldbws/ResponseTypes/DepartureItem.html +108 -0
- data/doc/Ldbws/ResponseTypes/DepartureItemWithDetails.html +108 -0
- data/doc/Ldbws/ResponseTypes/DeparturesBoard.html +105 -0
- data/doc/Ldbws/ResponseTypes/DeparturesBoardWithDetails.html +105 -0
- data/doc/Ldbws/ResponseTypes/Formation.html +108 -0
- data/doc/Ldbws/ResponseTypes/LoadingCategory.html +105 -0
- data/doc/Ldbws/ResponseTypes/Location.html +105 -0
- data/doc/Ldbws/ResponseTypes/ServiceDetails.html +143 -0
- data/doc/Ldbws/ResponseTypes/ServiceItem.html +132 -0
- data/doc/Ldbws/ResponseTypes/ServiceItemWithCallingPoints.html +106 -0
- data/doc/Ldbws/ResponseTypes/StationBoard.html +107 -0
- data/doc/Ldbws/ResponseTypes/StationBoardWithDetails.html +107 -0
- data/doc/Ldbws/ResponseTypes/ToiletAvailability.html +108 -0
- data/doc/Ldbws/ResponseTypes.html +91 -0
- data/doc/Ldbws/Service.html +538 -0
- data/doc/Ldbws.html +149 -0
- data/doc/README_md.html +159 -0
- data/doc/created.rid +19 -0
- data/doc/css/fonts.css +167 -0
- data/doc/css/rdoc.css +662 -0
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +165 -0
- data/doc/js/darkfish.js +84 -0
- data/doc/js/navigation.js +105 -0
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +110 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +229 -0
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +299 -0
- data/ldbws.gemspec +25 -0
- data/lib/ldbws/request/base.rb +69 -0
- data/lib/ldbws/request/get_departures_board.rb +54 -0
- data/lib/ldbws/request/get_service_details.rb +29 -0
- data/lib/ldbws/request/get_station_board.rb +60 -0
- data/lib/ldbws/response_types/base.rb +34 -0
- data/lib/ldbws/response_types/calling_point.rb +40 -0
- data/lib/ldbws/response_types/departures_board.rb +39 -0
- data/lib/ldbws/response_types/formation.rb +49 -0
- data/lib/ldbws/response_types/parsing_functions.rb +177 -0
- data/lib/ldbws/response_types/service_details.rb +69 -0
- data/lib/ldbws/response_types/service_item.rb +77 -0
- data/lib/ldbws/response_types/station_board.rb +50 -0
- data/lib/ldbws/service.rb +218 -0
- data/lib/ldbws/utils.rb +60 -0
- data/lib/ldbws/version.rb +4 -0
- data/lib/ldbws.rb +13 -0
- data/spec/response_types/parsing_spec.rb +46 -0
- data/spec/spec_helper.rb +4 -0
- metadata +224 -0
Binary file
|
data/doc/images/zoom.png
ADDED
Binary file
|
data/doc/index.html
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "./";
|
11
|
+
var index_rel_prefix = "./";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="./js/navigation.js" defer></script>
|
15
|
+
<script src="./js/search.js" defer></script>
|
16
|
+
<script src="./js/search_index.js" defer></script>
|
17
|
+
<script src="./js/searcher.js" defer></script>
|
18
|
+
<script src="./js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="./css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="./css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="file">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="./index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="./table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="./table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="./table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
|
40
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
41
|
+
<form action="#" method="get" accept-charset="utf-8">
|
42
|
+
<div id="search-field-wrapper">
|
43
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
44
|
+
aria-autocomplete="list" aria-controls="search-results"
|
45
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
46
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<ul id="search-results" aria-label="Search Results"
|
50
|
+
aria-busy="false" aria-expanded="false"
|
51
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
52
|
+
</form>
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="project-metadata">
|
58
|
+
|
59
|
+
<div id="fileindex-section" class="nav-section">
|
60
|
+
<h3>Pages</h3>
|
61
|
+
|
62
|
+
<ul class="link-list">
|
63
|
+
<li><a href="./LICENSE.html">LICENSE</a>
|
64
|
+
<li><a href="./README_md.html">README</a>
|
65
|
+
</ul>
|
66
|
+
</div>
|
67
|
+
|
68
|
+
<div id="classindex-section" class="nav-section">
|
69
|
+
<h3>Class and Module Index</h3>
|
70
|
+
|
71
|
+
<ul class="link-list">
|
72
|
+
<li><details open><summary><code><a href="./Ldbws.html">Ldbws</a></code></summary>
|
73
|
+
<ul class="link-list">
|
74
|
+
<li><details><summary><code><a href="./Ldbws/Request.html">Request</a></code></summary>
|
75
|
+
<ul class="link-list">
|
76
|
+
<li><code><a href="./Ldbws/Request/GetDeparturesBoard.html">GetDeparturesBoard</a></code>
|
77
|
+
<li><code><a href="./Ldbws/Request/GetDeparturesBoardWithDetails.html">GetDeparturesBoardWithDetails</a></code>
|
78
|
+
<li><code><a href="./Ldbws/Request/GetServiceDetails.html">GetServiceDetails</a></code>
|
79
|
+
<li><code><a href="./Ldbws/Request/GetStationBoard.html">GetStationBoard</a></code>
|
80
|
+
<li><code><a href="./Ldbws/Request/GetStationBoardWithDetails.html">GetStationBoardWithDetails</a></code>
|
81
|
+
</ul></details>
|
82
|
+
<li><details><summary><code><a href="./Ldbws/ResponseTypes.html">ResponseTypes</a></code></summary>
|
83
|
+
<ul class="link-list">
|
84
|
+
<li><code><a href="./Ldbws/ResponseTypes/BaseStationBoard.html">BaseStationBoard</a></code>
|
85
|
+
<li><code><a href="./Ldbws/ResponseTypes/CallingPoint.html">CallingPoint</a></code>
|
86
|
+
<li><code><a href="./Ldbws/ResponseTypes/Coach.html">Coach</a></code>
|
87
|
+
<li><code><a href="./Ldbws/ResponseTypes/DepartureItem.html">DepartureItem</a></code>
|
88
|
+
<li><code><a href="./Ldbws/ResponseTypes/DepartureItemWithDetails.html">DepartureItemWithDetails</a></code>
|
89
|
+
<li><code><a href="./Ldbws/ResponseTypes/DeparturesBoard.html">DeparturesBoard</a></code>
|
90
|
+
<li><code><a href="./Ldbws/ResponseTypes/DeparturesBoardWithDetails.html">DeparturesBoardWithDetails</a></code>
|
91
|
+
<li><code><a href="./Ldbws/ResponseTypes/Formation.html">Formation</a></code>
|
92
|
+
<li><code><a href="./Ldbws/ResponseTypes/LoadingCategory.html">LoadingCategory</a></code>
|
93
|
+
<li><code><a href="./Ldbws/ResponseTypes/Location.html">Location</a></code>
|
94
|
+
<li><code><a href="./Ldbws/ResponseTypes/ServiceDetails.html">ServiceDetails</a></code>
|
95
|
+
<li><code><a href="./Ldbws/ResponseTypes/ServiceItem.html">ServiceItem</a></code>
|
96
|
+
<li><code><a href="./Ldbws/ResponseTypes/ServiceItemWithCallingPoints.html">ServiceItemWithCallingPoints</a></code>
|
97
|
+
<li><code><a href="./Ldbws/ResponseTypes/StationBoard.html">StationBoard</a></code>
|
98
|
+
<li><code><a href="./Ldbws/ResponseTypes/StationBoardWithDetails.html">StationBoardWithDetails</a></code>
|
99
|
+
<li><code><a href="./Ldbws/ResponseTypes/ToiletAvailability.html">ToiletAvailability</a></code>
|
100
|
+
</ul></details>
|
101
|
+
<li><code><a href="./Ldbws/Service.html">Service</a></code>
|
102
|
+
</ul></details>
|
103
|
+
</div>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
</nav>
|
107
|
+
|
108
|
+
<main role="main">
|
109
|
+
|
110
|
+
|
111
|
+
<h1 id="label-ldbws-ruby">ldbws-ruby<span><a href="#label-ldbws-ruby">¶</a> <a href="#top">↑</a></span></h1>
|
112
|
+
|
113
|
+
<p>I’ll write a proper readme/howto at some point, but short version is that this is a Ruby wrapper around <a href="https://lite.realtime.nationalrail.co.uk/OpenLDBWS/">Network Rail‘s Live Departure Board web service</a> (LDBWS/OpenLDBWS)—I’ve trawled through their XSD files so you don’t have to =)</p>
|
114
|
+
|
115
|
+
<p>I built it for a project I’m hacking at + thought I’d release it into the world. It’s rough and ready right now, but it should be somewhat functional.</p>
|
116
|
+
|
117
|
+
<h2 id="label-HOWTO">HOWTO<span><a href="#label-HOWTO">¶</a> <a href="#top">↑</a></span></h2>
|
118
|
+
|
119
|
+
<p>All operations are supported, in <code>snake_case</code>, thus:</p>
|
120
|
+
|
121
|
+
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"path/to/ldbws"</span>
|
122
|
+
|
123
|
+
<span class="ruby-identifier">service</span> = <span class="ruby-constant">Ldbws</span>.<span class="ruby-identifier">service</span>(<span class="ruby-constant">YOUR_API_TOKEN</span>)
|
124
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">service</span>.<span class="ruby-identifier">get_departure_board</span>(<span class="ruby-value">crs:</span> <span class="ruby-string">"CDF"</span>)
|
125
|
+
|
126
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">"TIME PLAT TO"</span>
|
127
|
+
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">train_services</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">service</span><span class="ruby-operator">|</span>
|
128
|
+
<span class="ruby-identifier">printf</span>(
|
129
|
+
<span class="ruby-string">"%s %-2s %s (%s)\n"</span>,
|
130
|
+
<span class="ruby-identifier">service</span>.<span class="ruby-identifier">std</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">"%H:%M"</span>),
|
131
|
+
<span class="ruby-identifier">service</span>.<span class="ruby-identifier">platform</span> <span class="ruby-operator">||</span> <span class="ruby-string">"-"</span>,
|
132
|
+
<span class="ruby-identifier">service</span>.<span class="ruby-identifier">destination</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">name</span>,
|
133
|
+
<span class="ruby-identifier">service</span>.<span class="ruby-identifier">operator</span>
|
134
|
+
)
|
135
|
+
<span class="ruby-keyword">end</span>
|
136
|
+
|
137
|
+
<span class="ruby-comment"># TIME PLAT TO</span>
|
138
|
+
<span class="ruby-comment"># 17:32 - Penarth (Transport for Wales)</span>
|
139
|
+
<span class="ruby-comment"># 17:39 3 Swansea (Great Western Railway)</span>
|
140
|
+
<span class="ruby-comment"># 17:55 8 Barry (Transport for Wales)</span>
|
141
|
+
<span class="ruby-comment"># 17:56 2A Manchester Piccadilly (Transport for Wales)</span>
|
142
|
+
<span class="ruby-comment"># 18:01 6 Bargoed (Transport for Wales)</span>
|
143
|
+
<span class="ruby-comment"># [etc]</span>
|
144
|
+
</pre>
|
145
|
+
|
146
|
+
<h3 id="label-A+note+about+rate+limiting">A note about rate limiting<span><a href="#label-A+note+about+rate+limiting">¶</a> <a href="#top">↑</a></span></h3>
|
147
|
+
|
148
|
+
<p>LDBWS uses rate-limiting for free access: while this <em>probably</em> isn’t going to be an issue for the casual user, you may want to consider using a cache in front of this gem, just in case.</p>
|
149
|
+
|
150
|
+
<h2 id="label-Caveats">Caveats<span><a href="#label-Caveats">¶</a> <a href="#top">↑</a></span></h2>
|
151
|
+
|
152
|
+
<p>This is released into the world as-is. If you use it for something and end up missing your train, or do something that falls foul of the LDBWS terms of use, it’s not my fault :)</p>
|
153
|
+
<hr>
|
154
|
+
|
155
|
+
<p>Share and enjoy!</p>
|
156
|
+
|
157
|
+
</main>
|
158
|
+
|
159
|
+
|
160
|
+
<footer id="validator-badges" role="contentinfo">
|
161
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
162
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.5.0.
|
163
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
164
|
+
</footer>
|
165
|
+
|
data/doc/js/darkfish.js
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* Darkfish Page Functions
|
4
|
+
* $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
|
5
|
+
*
|
6
|
+
* Author: Michael Granger <mgranger@laika.com>
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
/* Provide console simulation for firebug-less environments */
|
11
|
+
/*
|
12
|
+
if (!("console" in window) || !("firebug" in console)) {
|
13
|
+
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
|
14
|
+
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
15
|
+
|
16
|
+
window.console = {};
|
17
|
+
for (var i = 0; i < names.length; ++i)
|
18
|
+
window.console[names[i]] = function() {};
|
19
|
+
};
|
20
|
+
*/
|
21
|
+
|
22
|
+
|
23
|
+
function showSource( e ) {
|
24
|
+
var target = e.target;
|
25
|
+
while (!target.classList.contains('method-detail')) {
|
26
|
+
target = target.parentNode;
|
27
|
+
}
|
28
|
+
if (typeof target !== "undefined" && target !== null) {
|
29
|
+
target = target.querySelector('.method-source-code');
|
30
|
+
}
|
31
|
+
if (typeof target !== "undefined" && target !== null) {
|
32
|
+
target.classList.toggle('active-menu')
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
function hookSourceViews() {
|
37
|
+
document.querySelectorAll('.method-heading').forEach(function (codeObject) {
|
38
|
+
codeObject.addEventListener('click', showSource);
|
39
|
+
});
|
40
|
+
};
|
41
|
+
|
42
|
+
function hookSearch() {
|
43
|
+
var input = document.querySelector('#search-field');
|
44
|
+
var result = document.querySelector('#search-results');
|
45
|
+
result.classList.remove("initially-hidden");
|
46
|
+
|
47
|
+
var search_section = document.querySelector('#search-section');
|
48
|
+
search_section.classList.remove("initially-hidden");
|
49
|
+
|
50
|
+
var search = new Search(search_data, input, result);
|
51
|
+
|
52
|
+
search.renderItem = function(result) {
|
53
|
+
var li = document.createElement('li');
|
54
|
+
var html = '';
|
55
|
+
|
56
|
+
// TODO add relative path to <script> per-page
|
57
|
+
html += '<p class="search-match"><a href="' + index_rel_prefix + this.escapeHTML(result.path) + '">' + this.hlt(result.title);
|
58
|
+
if (result.params)
|
59
|
+
html += '<span class="params">' + result.params + '</span>';
|
60
|
+
html += '</a>';
|
61
|
+
|
62
|
+
|
63
|
+
if (result.namespace)
|
64
|
+
html += '<p class="search-namespace">' + this.hlt(result.namespace);
|
65
|
+
|
66
|
+
if (result.snippet)
|
67
|
+
html += '<div class="search-snippet">' + result.snippet + '</div>';
|
68
|
+
|
69
|
+
li.innerHTML = html;
|
70
|
+
|
71
|
+
return li;
|
72
|
+
}
|
73
|
+
|
74
|
+
search.select = function(result) {
|
75
|
+
window.location.href = result.firstChild.firstChild.href;
|
76
|
+
}
|
77
|
+
|
78
|
+
search.scrollIntoView = search.scrollInWindow;
|
79
|
+
};
|
80
|
+
|
81
|
+
document.addEventListener('DOMContentLoaded', function() {
|
82
|
+
hookSourceViews();
|
83
|
+
hookSearch();
|
84
|
+
});
|
@@ -0,0 +1,105 @@
|
|
1
|
+
/*
|
2
|
+
* Navigation allows movement using the arrow keys through the search results.
|
3
|
+
*
|
4
|
+
* When using this library you will need to set scrollIntoView to the
|
5
|
+
* appropriate function for your layout. Use scrollInWindow if the container
|
6
|
+
* is not scrollable and scrollInElement if the container is a separate
|
7
|
+
* scrolling region.
|
8
|
+
*/
|
9
|
+
Navigation = new function() {
|
10
|
+
this.initNavigation = function() {
|
11
|
+
var _this = this;
|
12
|
+
|
13
|
+
document.addEventListener('keydown', function(e) {
|
14
|
+
_this.onkeydown(e);
|
15
|
+
});
|
16
|
+
|
17
|
+
this.navigationActive = true;
|
18
|
+
}
|
19
|
+
|
20
|
+
this.setNavigationActive = function(state) {
|
21
|
+
this.navigationActive = state;
|
22
|
+
}
|
23
|
+
|
24
|
+
this.onkeydown = function(e) {
|
25
|
+
if (!this.navigationActive) return;
|
26
|
+
switch(e.keyCode) {
|
27
|
+
case 37: //Event.KEY_LEFT:
|
28
|
+
if (this.moveLeft()) e.preventDefault();
|
29
|
+
break;
|
30
|
+
case 38: //Event.KEY_UP:
|
31
|
+
if (e.keyCode == 38 || e.ctrlKey) {
|
32
|
+
if (this.moveUp()) e.preventDefault();
|
33
|
+
}
|
34
|
+
break;
|
35
|
+
case 39: //Event.KEY_RIGHT:
|
36
|
+
if (this.moveRight()) e.preventDefault();
|
37
|
+
break;
|
38
|
+
case 40: //Event.KEY_DOWN:
|
39
|
+
if (e.keyCode == 40 || e.ctrlKey) {
|
40
|
+
if (this.moveDown()) e.preventDefault();
|
41
|
+
}
|
42
|
+
break;
|
43
|
+
case 13: //Event.KEY_RETURN:
|
44
|
+
if (this.current) e.preventDefault();
|
45
|
+
this.select(this.current);
|
46
|
+
break;
|
47
|
+
}
|
48
|
+
if (e.ctrlKey && e.shiftKey) this.select(this.current);
|
49
|
+
}
|
50
|
+
|
51
|
+
this.moveRight = function() {
|
52
|
+
}
|
53
|
+
|
54
|
+
this.moveLeft = function() {
|
55
|
+
}
|
56
|
+
|
57
|
+
this.move = function(isDown) {
|
58
|
+
}
|
59
|
+
|
60
|
+
this.moveUp = function() {
|
61
|
+
return this.move(false);
|
62
|
+
}
|
63
|
+
|
64
|
+
this.moveDown = function() {
|
65
|
+
return this.move(true);
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Scrolls to the given element in the scrollable element view.
|
70
|
+
*/
|
71
|
+
this.scrollInElement = function(element, view) {
|
72
|
+
var offset, viewHeight, viewScroll, height;
|
73
|
+
offset = element.offsetTop;
|
74
|
+
height = element.offsetHeight;
|
75
|
+
viewHeight = view.offsetHeight;
|
76
|
+
viewScroll = view.scrollTop;
|
77
|
+
|
78
|
+
if (offset - viewScroll + height > viewHeight) {
|
79
|
+
view.scrollTop = offset - viewHeight + height;
|
80
|
+
}
|
81
|
+
if (offset < viewScroll) {
|
82
|
+
view.scrollTop = offset;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
* Scrolls to the given element in the window. The second argument is
|
88
|
+
* ignored
|
89
|
+
*/
|
90
|
+
this.scrollInWindow = function(element, ignored) {
|
91
|
+
var offset, viewHeight, viewScroll, height;
|
92
|
+
offset = element.offsetTop;
|
93
|
+
height = element.offsetHeight;
|
94
|
+
viewHeight = window.innerHeight;
|
95
|
+
viewScroll = window.scrollY;
|
96
|
+
|
97
|
+
if (offset - viewScroll + height > viewHeight) {
|
98
|
+
window.scrollTo(window.scrollX, offset - viewHeight + height);
|
99
|
+
}
|
100
|
+
if (offset < viewScroll) {
|
101
|
+
window.scrollTo(window.scrollX, offset);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
Binary file
|
data/doc/js/search.js
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
Search = function(data, input, result) {
|
2
|
+
this.data = data;
|
3
|
+
this.input = input;
|
4
|
+
this.result = result;
|
5
|
+
|
6
|
+
this.current = null;
|
7
|
+
this.view = this.result.parentNode;
|
8
|
+
this.searcher = new Searcher(data.index);
|
9
|
+
this.init();
|
10
|
+
}
|
11
|
+
|
12
|
+
Search.prototype = Object.assign({}, Navigation, new function() {
|
13
|
+
var suid = 1;
|
14
|
+
|
15
|
+
this.init = function() {
|
16
|
+
var _this = this;
|
17
|
+
var observer = function(e) {
|
18
|
+
switch(e.keyCode) {
|
19
|
+
case 38: // Event.KEY_UP
|
20
|
+
case 40: // Event.KEY_DOWN
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
_this.search(_this.input.value);
|
24
|
+
};
|
25
|
+
this.input.addEventListener('keyup', observer);
|
26
|
+
this.input.addEventListener('click', observer); // mac's clear field
|
27
|
+
|
28
|
+
this.searcher.ready(function(results, isLast) {
|
29
|
+
_this.addResults(results, isLast);
|
30
|
+
})
|
31
|
+
|
32
|
+
this.initNavigation();
|
33
|
+
this.setNavigationActive(false);
|
34
|
+
}
|
35
|
+
|
36
|
+
this.search = function(value, selectFirstMatch) {
|
37
|
+
value = value.trim().toLowerCase();
|
38
|
+
if (value) {
|
39
|
+
this.setNavigationActive(true);
|
40
|
+
} else {
|
41
|
+
this.setNavigationActive(false);
|
42
|
+
}
|
43
|
+
|
44
|
+
if (value == '') {
|
45
|
+
this.lastQuery = value;
|
46
|
+
this.result.innerHTML = '';
|
47
|
+
this.result.setAttribute('aria-expanded', 'false');
|
48
|
+
this.setNavigationActive(false);
|
49
|
+
} else if (value != this.lastQuery) {
|
50
|
+
this.lastQuery = value;
|
51
|
+
this.result.setAttribute('aria-busy', 'true');
|
52
|
+
this.result.setAttribute('aria-expanded', 'true');
|
53
|
+
this.firstRun = true;
|
54
|
+
this.searcher.find(value);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
this.addResults = function(results, isLast) {
|
59
|
+
var target = this.result;
|
60
|
+
if (this.firstRun && (results.length > 0 || isLast)) {
|
61
|
+
this.current = null;
|
62
|
+
this.result.innerHTML = '';
|
63
|
+
}
|
64
|
+
|
65
|
+
for (var i=0, l = results.length; i < l; i++) {
|
66
|
+
var item = this.renderItem.call(this, results[i]);
|
67
|
+
item.setAttribute('id', 'search-result-' + target.childElementCount);
|
68
|
+
target.appendChild(item);
|
69
|
+
};
|
70
|
+
|
71
|
+
if (this.firstRun && results.length > 0) {
|
72
|
+
this.firstRun = false;
|
73
|
+
this.current = target.firstChild;
|
74
|
+
this.current.classList.add('search-selected');
|
75
|
+
}
|
76
|
+
//TODO: ECMAScript
|
77
|
+
//if (jQuery.browser.msie) this.$element[0].className += '';
|
78
|
+
|
79
|
+
if (isLast) this.result.setAttribute('aria-busy', 'false');
|
80
|
+
}
|
81
|
+
|
82
|
+
this.move = function(isDown) {
|
83
|
+
if (!this.current) return;
|
84
|
+
var next = isDown ? this.current.nextElementSibling : this.current.previousElementSibling;
|
85
|
+
if (next) {
|
86
|
+
this.current.classList.remove('search-selected');
|
87
|
+
next.classList.add('search-selected');
|
88
|
+
this.input.setAttribute('aria-activedescendant', next.getAttribute('id'));
|
89
|
+
this.scrollIntoView(next, this.view);
|
90
|
+
this.current = next;
|
91
|
+
this.input.value = next.firstChild.firstChild.text;
|
92
|
+
this.input.select();
|
93
|
+
}
|
94
|
+
return true;
|
95
|
+
}
|
96
|
+
|
97
|
+
this.hlt = function(html) {
|
98
|
+
return this.escapeHTML(html).
|
99
|
+
replace(/\u0001/g, '<em>').
|
100
|
+
replace(/\u0002/g, '</em>');
|
101
|
+
}
|
102
|
+
|
103
|
+
this.escapeHTML = function(html) {
|
104
|
+
return html.replace(/[&<>"`']/g, function(c) {
|
105
|
+
return '&#' + c.charCodeAt(0) + ';';
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
});
|
110
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
var search_data = {"index":{"searchIndex":["ldbws","request","getdeparturesboard","getdeparturesboardwithdetails","getservicedetails","getstationboard","getstationboardwithdetails","responsetypes","basestationboard","callingpoint","coach","departureitem","departureitemwithdetails","departuresboard","departuresboardwithdetails","formation","loadingcategory","location","servicedetails","serviceitem","serviceitemwithcallingpoints","stationboard","stationboardwithdetails","toiletavailability","service","get_arr_board_with_details()","get_arr_dep_board_with_details()","get_arrival_board()","get_arrival_board_with_details()","get_arrival_departure_board()","get_arrival_departure_board_with_details()","get_dep_board_with_details()","get_departure_board()","get_departure_board_with_details()","get_fastest_departures_with_details()","get_next_departures()","get_next_departures_with_details()","get_service_details()","new()","service()","license","readme"],"longSearchIndex":["ldbws","ldbws::request","ldbws::request::getdeparturesboard","ldbws::request::getdeparturesboardwithdetails","ldbws::request::getservicedetails","ldbws::request::getstationboard","ldbws::request::getstationboardwithdetails","ldbws::responsetypes","ldbws::responsetypes::basestationboard","ldbws::responsetypes::callingpoint","ldbws::responsetypes::coach","ldbws::responsetypes::departureitem","ldbws::responsetypes::departureitemwithdetails","ldbws::responsetypes::departuresboard","ldbws::responsetypes::departuresboardwithdetails","ldbws::responsetypes::formation","ldbws::responsetypes::loadingcategory","ldbws::responsetypes::location","ldbws::responsetypes::servicedetails","ldbws::responsetypes::serviceitem","ldbws::responsetypes::serviceitemwithcallingpoints","ldbws::responsetypes::stationboard","ldbws::responsetypes::stationboardwithdetails","ldbws::responsetypes::toiletavailability","ldbws::service","ldbws::service#get_arr_board_with_details()","ldbws::service#get_arr_dep_board_with_details()","ldbws::service#get_arrival_board()","ldbws::service#get_arrival_board_with_details()","ldbws::service#get_arrival_departure_board()","ldbws::service#get_arrival_departure_board_with_details()","ldbws::service#get_dep_board_with_details()","ldbws::service#get_departure_board()","ldbws::service#get_departure_board_with_details()","ldbws::service#get_fastest_departures_with_details()","ldbws::service#get_next_departures()","ldbws::service#get_next_departures_with_details()","ldbws::service#get_service_details()","ldbws::service::new()","ldbws::service()","",""],"info":[["Ldbws","","Ldbws.html","","<p>Provides a Ruby abstraction around the UK’s Network Rail live departure board webservice (LDBWS). See …\n"],["Ldbws::Request","","Ldbws/Request.html","",""],["Ldbws::Request::GetDeparturesBoard","","Ldbws/Request/GetDeparturesBoard.html","","<p>Requests a departure board for a station, filtered by departures to one or many other stations. Corresponds …\n"],["Ldbws::Request::GetDeparturesBoardWithDetails","","Ldbws/Request/GetDeparturesBoardWithDetails.html","","<p>Requests a departure board for a statuion, filtered by departures to one or more other stations. This …\n"],["Ldbws::Request::GetServiceDetails","","Ldbws/Request/GetServiceDetails.html","","<p>Returns details about a particular service. Corresponds to <code>GetServiceDetailsResponse</code> in the LDBWS schema. …\n"],["Ldbws::Request::GetStationBoard","","Ldbws/Request/GetStationBoard.html","","<p>Returns an arrival or departure board for a given station. Corresponds to <code>GetStationBoardRequest</code> in the …\n"],["Ldbws::Request::GetStationBoardWithDetails","","Ldbws/Request/GetStationBoardWithDetails.html","","<p>Returns an arrival or departure board for a given station with full service details. Corresponds to …\n"],["Ldbws::ResponseTypes","","Ldbws/ResponseTypes.html","",""],["Ldbws::ResponseTypes::BaseStationBoard","","Ldbws/ResponseTypes/BaseStationBoard.html","","<p>Base station board information. This does not directly correspond to a type in LDBWS.\n<p>Properties\n"],["Ldbws::ResponseTypes::CallingPoint","","Ldbws/ResponseTypes/CallingPoint.html","","<p>Represents a calling point in the LDBWS.\n<p>Properties\n<p>location_name — the name of the station\n"],["Ldbws::ResponseTypes::Coach","","Ldbws/ResponseTypes/Coach.html","","<p>Information about an individual coach in the train.\n<p>Properties\n<p>number — the coach number or identifier\n"],["Ldbws::ResponseTypes::DepartureItem","","Ldbws/ResponseTypes/DepartureItem.html","","<p>Represents an item on a departure board.\n<p>Properties\n<p>crs — the CRS for the item\n"],["Ldbws::ResponseTypes::DepartureItemWithDetails","","Ldbws/ResponseTypes/DepartureItemWithDetails.html","","<p>Represents an item on a departure board with additional details.\n<p>Properties\n<p>crs — the CRS for the item\n"],["Ldbws::ResponseTypes::DeparturesBoard","","Ldbws/ResponseTypes/DeparturesBoard.html","","<p>Represents a departures board.\n<p>Properties\n<p>departures — a list of departures.\n"],["Ldbws::ResponseTypes::DeparturesBoardWithDetails","","Ldbws/ResponseTypes/DeparturesBoardWithDetails.html","","<p>Represents a departures board with additional details.\n<p>Properties\n<p>departures — a list of departures.\n"],["Ldbws::ResponseTypes::Formation","","Ldbws/ResponseTypes/Formation.html","","<p>Information about the formation of a train\n<p>Properties\n<p>loading_category — how heavily-loaded the train is. …\n"],["Ldbws::ResponseTypes::LoadingCategory","","Ldbws/ResponseTypes/LoadingCategory.html","","<p>The loading category of a train\n<p>Properties\n<p>code, colour, image — \n"],["Ldbws::ResponseTypes::Location","","Ldbws/ResponseTypes/Location.html","","<p>Represents a location in LDBWS.\n<p>Properties\n<p>name, crs, via — \n"],["Ldbws::ResponseTypes::ServiceDetails","","Ldbws/ResponseTypes/ServiceDetails.html","","<p>Represents details about a service in LDBWS.\n<p>Properties\n"],["Ldbws::ResponseTypes::ServiceItem","","Ldbws/ResponseTypes/ServiceItem.html","","<p>Represents a service item in LDBWS.\n<p>Properties\n<p>sta — the scheduled arrival time as a Time object\n"],["Ldbws::ResponseTypes::ServiceItemWithCallingPoints","","Ldbws/ResponseTypes/ServiceItemWithCallingPoints.html","","<p>Represents a service item with additional details in LDBWS: extends ServiceItem.\n<p>Properties\n<p>As ServiceItem …\n"],["Ldbws::ResponseTypes::StationBoard","","Ldbws/ResponseTypes/StationBoard.html","","<p>Represents a station arrival/departure board in LDBWS.\n<p>Properties\n<p>As BaseStationBoard, and additionally: …\n"],["Ldbws::ResponseTypes::StationBoardWithDetails","","Ldbws/ResponseTypes/StationBoardWithDetails.html","","<p>Represents a station arrival/departure board with additional details in LDBWS.\n<p>Properties\n<p>As BaseStationBoard …\n"],["Ldbws::ResponseTypes::ToiletAvailability","","Ldbws/ResponseTypes/ToiletAvailability.html","","<p>The availability of an individual toilet on a train\n<p>Properties\n<p>type — the type of toilet\n"],["Ldbws::Service","","Ldbws/Service.html","","<p>A wrapper around the National Rail Live Departure Boards Webservice (LDBWS) API.\n<p>API methods are pretty …\n"],["get_arr_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_arr_board_with_details","(params)","<p>Retrieves a detailed station arrival board.\n<p>Parameters are validated using GetStationBoardWithDetails …\n"],["get_arr_dep_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_arr_dep_board_with_details","(params)","<p>Retrieves a detailed station arrival + departures board.\n<p>Parameters are validated using GetStationBoardWithDetails …\n"],["get_arrival_board","Ldbws::Service","Ldbws/Service.html#method-i-get_arrival_board","(params)","<p>Retrieves a station arrival board.\n<p>Parameters are validated using GetStationBoard, returns a StationBoard …\n"],["get_arrival_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_arrival_board_with_details","(params)",""],["get_arrival_departure_board","Ldbws::Service","Ldbws/Service.html#method-i-get_arrival_departure_board","(params)","<p>Retrieves a station arrival + departure board.\n<p>Parameters are validated using GetStationBoard, returns …\n"],["get_arrival_departure_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_arrival_departure_board_with_details","(params)",""],["get_dep_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_dep_board_with_details","(params)","<p>Retrieves a detailed station departure board.\n<p>Parameters are validated using GetStationBoardWithDetails …\n"],["get_departure_board","Ldbws::Service","Ldbws/Service.html#method-i-get_departure_board","(params)","<p>Retrieves a station departure board.\n<p>Parameters are validated using GetStationBoard, returns a StationBoard …\n"],["get_departure_board_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_departure_board_with_details","(params)",""],["get_fastest_departures_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_fastest_departures_with_details","(params)","<p>Retrieves detailed information about the fastest departures from one station to one or many others.\n<p>Parameters …\n"],["get_next_departures","Ldbws::Service","Ldbws/Service.html#method-i-get_next_departures","(params)","<p>Retrieves the next departures from one station to one or many others.\n<p>Parameters are validated using …\n"],["get_next_departures_with_details","Ldbws::Service","Ldbws/Service.html#method-i-get_next_departures_with_details","(params)","<p>Retrieves detailed information about the next departures from one station to one or many others.\n<p>Parameters …\n"],["get_service_details","Ldbws::Service","Ldbws/Service.html#method-i-get_service_details","(params)","<p>Retrieves information about a specific service.\n<p>Parameters are validated using GetServiceDetails, returns …\n"],["new","Ldbws::Service","Ldbws/Service.html#method-c-new","(token)","<p>Creates a service object.\n<p>Parameters\n<p>token — the API token used to connect to the service\n"],["service","Ldbws","Ldbws.html#method-c-service","(token)","<p>Helper method that returns an instance of [Service].\n<p>Parameters\n<p>token — the API token used to connect to …\n"],["LICENSE","","LICENSE.html","","<p>MIT License\n<p>Copyright © 2022 Jon Pearse\n<p>Permission is hereby granted, free of charge, to any person obtaining …\n"],["README","","README_md.html","","<p>ldbws-ruby\n<p>I’ll write a proper readme/howto at some point, but short version is that this is a Ruby wrapper …\n"]]}}
|
Binary file
|