ruby-irail 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,113 +4,77 @@ module IRail::API
4
4
  STATIONS_URI = "stations/"
5
5
  CONNECTIONS_URI = "connections/"
6
6
  VEHICLE_URI = "vehicle/"
7
- LIVEBOARD_URI = "liveboard/"
7
+ DEPARTURES_URI = "liveboard/"
8
+ ARRIVALS_URI = "liveboard/"
8
9
 
9
10
  def stations(options = {})
10
- station_list_url = build_station_list_url
11
- xml_station_list = get_station_list(station_list_url, options)
12
- IRail::NMBS::DocumentParser.parse_stations(xml_station_list)
11
+ get_resource(:stations, options)
13
12
  end
14
13
 
15
14
  def connections(origin_station, destination_station, options = {})
16
- connections_url = build_connections_url
17
- xml_connections = get_connections(connections_url, origin_station, destination_station, options)
18
- IRail::NMBS::DocumentParser.parse_connections(xml_connections)
15
+ options = build_connections_option_hash(origin_station, destination_station, options)
16
+ get_resource(:connections, options)
19
17
  end
20
18
 
21
19
  def vehicle(vehicle_id, options = {})
22
- vehicle_url = build_vehicle_url
23
- xml_vehicle = get_vehicle(vehicle_url, vehicle_id, options)
24
- IRail::NMBS::DocumentParser.parse_vehicle(xml_vehicle)
20
+ options = build_vehicle_option_hash(vehicle_id, options)
21
+ get_resource(:vehicle, options)
25
22
  end
26
23
 
27
24
  def departures(station_id, options = {})
28
- liveboard_url = build_liveboard_url
29
- xml_departures = get_departures(liveboard_url, station_id, options)
30
- IRail::NMBS::DocumentParser.parse_liveboard(xml_departures)
25
+ options = build_departures_option_hash(station_id, options)
26
+ get_resource(:departures, options)
31
27
  end
32
28
 
33
29
  def arrivals(station_id, options = {})
34
- liveboard_url = build_liveboard_url
35
- xml_arrivals = get_arrivals(liveboard_url, station_id, options)
36
- IRail::NMBS::DocumentParser.parse_liveboard(xml_arrivals)
37
- end
38
-
39
- def get_station_list(station_list_url, options = {})
40
- options = { :query => options } if options.any?
41
- IRail::Request.get(station_list_url, options)
42
- end
43
-
44
- def get_connections(connections_url, origin_station, destination_station, options = {})
45
- options = build_connections_option_hash(origin_station, destination_station, options)
46
- IRail::Request.get(connections_url, options)
30
+ options = build_arrivals_option_hash(station_id, options)
31
+ get_resource(:arrivals, options)
47
32
  end
48
33
 
49
- def get_vehicle(vehicle_url, vehicle_id, options = {})
50
- options = build_vehicle_option_hash(vehicle_id, options)
51
- IRail::Request.get(vehicle_url, options)
34
+ def get_resource(resource, options)
35
+ uri = IRail::API::NMBS.const_get("#{resource.upcase}_URI")
36
+ url = build_url(uri)
37
+ xml = call_api(url, options)
38
+ IRail::NMBS::XMLParser.send("parse_#{resource}", xml)
52
39
  end
53
40
 
54
- def get_departures(liveboard_url, station_id, options = {})
55
- options = build_departures_option_hash(station_id, options)
56
- IRail::Request.get(liveboard_url, options)
41
+ def call_api(url, options = {})
42
+ options = build_query_options_hash(options)
43
+ IRail::Request.get(url, options)
57
44
  end
58
45
 
59
- def get_arrivals(liveboard_url, station_id, options = {})
60
- options = build_arrivals_option_hash(station_id, options)
61
- IRail::Request.get(liveboard_url, options)
46
+ private
47
+ def build_query_options_hash(options)
48
+ { :query => options }
62
49
  end
63
50
 
64
- private
65
51
  def build_connections_option_hash(origin_station, destination_station, options = {})
66
- {
67
- :query => options.merge({
68
- :from => origin_station.name,
69
- :to => destination_station.name
70
- })
71
- }
52
+ options.merge({
53
+ :from => origin_station.name,
54
+ :to => destination_station.name
55
+ })
72
56
  end
73
57
 
74
58
  def build_vehicle_option_hash(vehicle_id, options = {})
75
- {
76
- :query => options.merge({
77
- :id => vehicle_id
78
- })
79
- }
59
+ options.merge({ :id => vehicle_id })
80
60
  end
81
61
 
82
62
  def build_departures_option_hash(station_id, options = {})
83
- {
84
- :query => options.merge({
85
- :id => station_id,
86
- :arrdep => "DEP"
87
- })
88
- }
63
+ options.merge({
64
+ :id => station_id,
65
+ :arrdep => "DEP"
66
+ })
89
67
  end
90
68
 
91
69
  def build_arrivals_option_hash(station_id, options = {})
92
- {
93
- :query => options.merge({
94
- :id => station_id,
95
- :arrdep => "ARR"
96
- })
97
- }
98
- end
99
-
100
- def build_station_list_url
101
- [API_URL, STATIONS_URI].join('/')
102
- end
103
-
104
- def build_connections_url
105
- [API_URL, CONNECTIONS_URI].join('/')
106
- end
107
-
108
- def build_vehicle_url
109
- [API_URL, VEHICLE_URI].join('/')
70
+ options.merge({
71
+ :id => station_id,
72
+ :arrdep => "ARR"
73
+ })
110
74
  end
111
75
 
112
- def build_liveboard_url
113
- [API_URL, LIVEBOARD_URI].join('/')
76
+ def build_url(uri)
77
+ [API_URL, uri].join('/')
114
78
  end
115
79
  end
116
80
  end
@@ -1,23 +1,23 @@
1
1
  module IRail::NMBS
2
- class DocumentParser
2
+ class XMLParser
3
3
  STATION_XPATH = "//station"
4
4
  CONNECTION_XPATH = "//connection"
5
5
  VEHICLE_XPATH = "//vehicleinformation"
6
6
 
7
7
  def self.parse_stations(xml_string)
8
- xml_stations(xml_string).inject([]) do |stations, xml_station|
8
+ xml_payload(xml_string, STATION_XPATH).inject([]) do |stations, xml_station|
9
9
  stations << IRail::NMBS::Station.from_xml(xml_station.to_s)
10
10
  end
11
11
  end
12
12
 
13
13
  def self.parse_connections(xml_string)
14
- xml_connections(xml_string).inject([]) do |connections, xml_connection|
14
+ xml_payload(xml_string, CONNECTION_XPATH).inject([]) do |connections, xml_connection|
15
15
  connections << IRail::NMBS::Connection.from_xml(xml_connection.to_s)
16
16
  end
17
17
  end
18
18
 
19
19
  def self.parse_vehicle(xml_string)
20
- vehicle = xml_vehicle(xml_string)
20
+ vehicle = xml_payload(xml_string, VEHICLE_XPATH)
21
21
  IRail::NMBS::VehicleInformation.from_xml(vehicle.to_s)
22
22
  end
23
23
 
@@ -25,19 +25,14 @@ module IRail::NMBS
25
25
  IRail::NMBS::Liveboard.from_xml(xml_string)
26
26
  end
27
27
 
28
- def self.xml_vehicle(xml_string)
29
- xml_payload = Nokogiri::XML(xml_string)
30
- xml_payload.xpath(VEHICLE_XPATH)
31
- end
32
-
33
- def self.xml_stations(xml_string)
34
- xml_payload = Nokogiri::XML(xml_string)
35
- xml_payload.xpath(STATION_XPATH)
28
+ class << self
29
+ alias :parse_departures :parse_liveboard
30
+ alias :parse_arrivals :parse_liveboard
36
31
  end
37
32
 
38
- def self.xml_connections(xml_string)
33
+ def self.xml_payload(xml_string, xpath)
39
34
  xml_payload = Nokogiri::XML(xml_string)
40
- xml_payload.xpath(CONNECTION_XPATH)
35
+ xml_payload.xpath(xpath)
41
36
  end
42
37
  end
43
38
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IRail
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -9,21 +9,28 @@ describe IRail::API::NMBS do
9
9
  let(:connections_url) { mock("Connections url") }
10
10
  let(:xml_connections) { mock("Xml connections") }
11
11
  let(:connections) { mock("Connections") }
12
+ let(:connections_options) { mock("Connections options") }
12
13
  let(:options) { mock("Options") }
13
14
 
14
15
  before :each do
15
- irail.stub(:build_connections_url => connections_url)
16
- irail.stub(:get_connections => xml_connections)
17
- IRail::NMBS::DocumentParser.stub(:parse_connections => connections)
16
+ irail.stub(:build_url => connections_url)
17
+ irail.stub(:call_api => xml_connections)
18
+ irail.stub(:build_connections_option_hash => connections_options)
19
+ IRail::NMBS::XMLParser.stub(:parse_connections => connections)
18
20
  end
19
21
 
20
22
  it "builds the connections url" do
21
- irail.should_receive(:build_connections_url)
23
+ irail.should_receive(:build_url).with(IRail::API::NMBS::CONNECTIONS_URI)
22
24
  irail.connections(origin_station, destination_station)
23
25
  end
24
26
 
27
+ it "builds the connections options" do
28
+ irail.should_receive(:build_connections_option_hash).with(origin_station, destination_station, options)
29
+ irail.connections(origin_station, destination_station, options)
30
+ end
31
+
25
32
  it "gets the connections" do
26
- irail.should_receive(:get_connections).with(connections_url, origin_station, destination_station, options)
33
+ irail.should_receive(:call_api).with(connections_url, connections_options)
27
34
  irail.connections(origin_station, destination_station, options)
28
35
  end
29
36
 
@@ -33,25 +40,32 @@ describe IRail::API::NMBS do
33
40
  end
34
41
 
35
42
  describe :vehicle do
36
- let(:vehicle_id) { mock("Vehicle id") }
37
- let(:vehicle_url) { mock("Vehicle url") }
38
- let(:xml_vehicle) { mock("Xml vehicle") }
39
- let(:vehicle) { mock("vehicle") }
40
- let(:options) { mock("Options") }
43
+ let(:vehicle_id) { mock("Vehicle id") }
44
+ let(:vehicle_url) { mock("Vehicle url") }
45
+ let(:xml_vehicle) { mock("Xml vehicle") }
46
+ let(:vehicle) { mock("vehicle") }
47
+ let(:options) { mock("Options") }
48
+ let(:vehicle_options) { mock("Vehicle options") }
41
49
 
42
50
  before :each do
43
- irail.stub(:build_vehicle_url => vehicle_url)
44
- irail.stub(:get_vehicle => xml_vehicle)
45
- IRail::NMBS::DocumentParser.stub(:parse_vehicle => vehicle)
51
+ irail.stub(:build_url => vehicle_url)
52
+ irail.stub(:call_api => xml_vehicle)
53
+ irail.stub(:build_vehicle_option_hash => vehicle_options)
54
+ IRail::NMBS::XMLParser.stub(:parse_vehicle => vehicle)
46
55
  end
47
56
 
48
57
  it "builds the vehicle url" do
49
- irail.should_receive(:build_vehicle_url)
58
+ irail.should_receive(:build_url).with(IRail::API::NMBS::VEHICLE_URI)
50
59
  irail.vehicle(vehicle_id)
51
60
  end
52
61
 
62
+ it "builds the vehicle options" do
63
+ irail.should_receive(:build_vehicle_option_hash).with(vehicle_id, options)
64
+ irail.vehicle(vehicle_id, options)
65
+ end
66
+
53
67
  it "gets the vehicle" do
54
- irail.should_receive(:get_vehicle).with(vehicle_url, vehicle_id, options)
68
+ irail.should_receive(:call_api).with(vehicle_url, vehicle_options)
55
69
  irail.vehicle(vehicle_id, options)
56
70
  end
57
71
 
@@ -67,18 +81,18 @@ describe IRail::API::NMBS do
67
81
  let(:options) { mock("Options") }
68
82
 
69
83
  before :each do
70
- irail.stub(:build_station_list_url => station_list_url)
71
- irail.stub(:get_station_list => xml_station_list)
72
- IRail::NMBS::DocumentParser.stub(:parse_stations => stations)
84
+ irail.stub(:build_url => station_list_url)
85
+ irail.stub(:call_api => xml_station_list)
86
+ IRail::NMBS::XMLParser.stub(:parse_stations => stations)
73
87
  end
74
88
 
75
89
  it "builds the station list url" do
76
- irail.should_receive(:build_station_list_url)
90
+ irail.should_receive(:build_url).with(IRail::API::NMBS::STATIONS_URI)
77
91
  irail.stations(options)
78
92
  end
79
93
 
80
94
  it "gets the xml station list" do
81
- irail.should_receive(:get_station_list).with(station_list_url, options)
95
+ irail.should_receive(:call_api).with(station_list_url, options)
82
96
  irail.stations(options)
83
97
  end
84
98
 
@@ -93,20 +107,27 @@ describe IRail::API::NMBS do
93
107
  let(:options) { mock("Options") }
94
108
  let(:liveboard) { mock("Liveboard") }
95
109
  let(:xml_departures) { mock("Xml departures") }
110
+ let(:departures_options) { mock("Departures options") }
96
111
 
97
112
  before :each do
98
- irail.stub(:build_liveboard_url => liveboard_url)
99
- irail.stub(:get_departures => xml_departures)
100
- IRail::NMBS::DocumentParser.stub(:parse_liveboard => liveboard)
113
+ irail.stub(:build_url => liveboard_url)
114
+ irail.stub(:call_api => xml_departures)
115
+ irail.stub(:build_departures_option_hash => departures_options)
116
+ IRail::NMBS::XMLParser.stub(:parse_departures => liveboard)
101
117
  end
102
118
 
103
119
  it "builds the liveboard url" do
104
- irail.should_receive(:build_liveboard_url)
120
+ irail.should_receive(:build_url).with(IRail::API::NMBS::DEPARTURES_URI)
121
+ irail.departures(station_id, options)
122
+ end
123
+
124
+ it "builds the departures options" do
125
+ irail.should_receive(:build_departures_option_hash).with(station_id, options)
105
126
  irail.departures(station_id, options)
106
127
  end
107
128
 
108
129
  it "gets the departures xml" do
109
- irail.should_receive(:get_departures).with(liveboard_url, station_id, options)
130
+ irail.should_receive(:call_api).with(liveboard_url, departures_options)
110
131
  irail.departures(station_id, options)
111
132
  end
112
133
 
@@ -121,20 +142,27 @@ describe IRail::API::NMBS do
121
142
  let(:options) { mock("Options") }
122
143
  let(:liveboard) { mock("Liveboard") }
123
144
  let(:xml_arrivals) { mock("Xml arrivals") }
145
+ let(:arrivals_options) { mock("Arrivals options") }
124
146
 
125
147
  before :each do
126
- irail.stub(:build_liveboard_url => liveboard_url)
127
- irail.stub(:get_arrivals => xml_arrivals)
128
- IRail::NMBS::DocumentParser.stub(:parse_liveboard => liveboard)
148
+ irail.stub(:build_url => liveboard_url)
149
+ irail.stub(:call_api => xml_arrivals)
150
+ irail.stub(:build_arrivals_option_hash => arrivals_options)
151
+ IRail::NMBS::XMLParser.stub(:parse_arrivals => liveboard)
129
152
  end
130
153
 
131
154
  it "builds the liveboard url" do
132
- irail.should_receive(:build_liveboard_url)
155
+ irail.should_receive(:build_url).with(IRail::API::NMBS::ARRIVALS_URI)
156
+ irail.arrivals(station_id, options)
157
+ end
158
+
159
+ it "builds the departures options" do
160
+ irail.should_receive(:build_arrivals_option_hash).with(station_id, options)
133
161
  irail.arrivals(station_id, options)
134
162
  end
135
163
 
136
164
  it "gets the arrivals xml" do
137
- irail.should_receive(:get_arrivals).with(liveboard_url, station_id, options)
165
+ irail.should_receive(:call_api).with(liveboard_url, arrivals_options)
138
166
  irail.arrivals(station_id, options)
139
167
  end
140
168
 
@@ -143,121 +171,29 @@ describe IRail::API::NMBS do
143
171
  end
144
172
  end
145
173
 
146
- describe :get_connections do
147
- let(:origin_station) { mock("Origin station") }
148
- let(:destination_station) { mock("Destination station") }
149
- let(:connections_url) { mock("Connections url") }
150
- let(:options_hash) { mock("Options hash") }
151
- let(:response) { mock("Response") }
152
- let(:options) { mock("Oprions") }
153
-
154
- before :each do
155
- irail.stub(:build_connections_option_hash => options_hash)
156
- IRail::Request.stub(:get => response)
157
- end
158
-
159
- it "builds the options hash" do
160
- irail.should_receive(:build_connections_option_hash).with(origin_station, destination_station, options)
161
- irail.get_connections(connections_url, origin_station, destination_station, options)
162
- end
163
-
164
- it "calls the connections url through a get request" do
165
- IRail::Request.should_receive(:get).with(connections_url, options_hash)
166
- irail.get_connections(connections_url, origin_station, destination_station)
167
- end
168
-
169
- it "returns the response" do
170
- irail.get_connections(connections_url, origin_station, destination_station).should eql response
171
- end
172
- end
173
-
174
- describe :get_departures do
175
- let(:station_id) { mock("Station id") }
176
- let(:options) { mock("Options") }
177
- let(:liveboard_url) { mock("Liveboard url") }
174
+ describe :call_api do
175
+ let(:url) { mock("Connections url") }
178
176
  let(:options_hash) { mock("Options hash") }
179
177
  let(:response) { mock("Response") }
178
+ let(:options) { mock("Oprions") }
180
179
 
181
180
  before :each do
182
- irail.stub(:build_departures_option_hash => options_hash)
181
+ irail.stub(:build_query_options_hash => options_hash)
183
182
  IRail::Request.stub(:get => response)
184
183
  end
185
184
 
186
185
  it "builds the options hash" do
187
- irail.should_receive(:build_departures_option_hash).with(station_id, options)
188
- irail.get_departures(liveboard_url, station_id, options)
186
+ irail.should_receive(:build_query_options_hash).with(options)
187
+ irail.call_api(url, options)
189
188
  end
190
189
 
191
190
  it "calls the connections url through a get request" do
192
- IRail::Request.should_receive(:get).with(liveboard_url, options_hash)
193
- irail.get_departures(liveboard_url, station_id, options)
191
+ IRail::Request.should_receive(:get).with(url, options_hash)
192
+ irail.call_api(url, options)
194
193
  end
195
194
 
196
195
  it "returns the response" do
197
- irail.get_departures(liveboard_url, station_id, options).should eql response
198
- end
199
- end
200
-
201
- describe :get_arrivals do
202
- let(:station_id) { mock("Station id") }
203
- let(:options) { mock("Options") }
204
- let(:liveboard_url) { mock("Liveboard url") }
205
- let(:options_hash) { mock("Options hash") }
206
- let(:response) { mock("Response") }
207
-
208
- before :each do
209
- irail.stub(:build_arrivals_option_hash => options_hash)
210
- IRail::Request.stub(:get => response)
211
- end
212
-
213
- it "builds the options hash" do
214
- irail.should_receive(:build_arrivals_option_hash).with(station_id, options)
215
- irail.get_arrivals(liveboard_url, station_id, options)
216
- end
217
-
218
- it "calls the connections url through a get request" do
219
- IRail::Request.should_receive(:get).with(liveboard_url, options_hash)
220
- irail.get_arrivals(liveboard_url, station_id, options)
221
- end
222
-
223
- it "returns the response" do
224
- irail.get_arrivals(liveboard_url, station_id, options).should eql response
225
- end
226
- end
227
-
228
- describe :get_station_list do
229
- let(:url) { mock("Url") }
230
- let(:response) { mock("Response") }
231
-
232
- before :each do
233
- IRail::Request.stub(:get => response)
234
- end
235
-
236
- context "when there are no options" do
237
- let(:options) { {} }
238
-
239
- it "calls the station list url through a get request" do
240
- IRail::Request.should_receive(:get).with(url, options)
241
- irail.get_station_list(url, options)
242
- end
243
-
244
- it "returns the response" do
245
- irail.get_station_list(url, options).should eql response
246
- end
247
- end
248
-
249
- context "when there are options" do
250
- let(:options) { {:a => 1} }
251
-
252
- it "calls the station list url with query options" do
253
- expected_options = { :query => options }
254
- IRail::Request.should_receive(:get).with(url, expected_options)
255
- irail.get_station_list(url, options)
256
- end
257
-
258
- it "returns the response" do
259
- irail.get_station_list(url, options).should eql response
260
- end
196
+ irail.call_api(url, options).should eql response
261
197
  end
262
198
  end
263
199
  end
@@ -1,6 +1,6 @@
1
- require_relative "../../../../lib/ruby-irail/packages/nmbs/parser/document_parser.rb"
1
+ require_relative "../../../../lib/ruby-irail/packages/nmbs/parser/xml_parser.rb"
2
2
 
3
- describe IRail::NMBS::DocumentParser do
3
+ describe IRail::NMBS::XMLParser do
4
4
  module Nokogiri
5
5
  module XML
6
6
  end
@@ -28,23 +28,23 @@ describe IRail::NMBS::DocumentParser do
28
28
 
29
29
  it "gets the xml payload from the string passed as parameter" do
30
30
  Nokogiri.should_receive(:XML).with(xml_string)
31
- IRail::NMBS::DocumentParser.parse_stations(xml_string)
31
+ IRail::NMBS::XMLParser.parse_stations(xml_string)
32
32
  end
33
33
 
34
34
  it "extracts the stations from the xml payload" do
35
- xml_payload.should_receive(:xpath).with(IRail::NMBS::DocumentParser::STATION_XPATH)
36
- IRail::NMBS::DocumentParser.parse_stations(xml_string)
35
+ xml_payload.should_receive(:xpath).with(IRail::NMBS::XMLParser::STATION_XPATH)
36
+ IRail::NMBS::XMLParser.parse_stations(xml_string)
37
37
  end
38
38
 
39
39
  it "creates a new station for all parsed station attributes" do
40
40
  stations.each do |station|
41
41
  IRail::NMBS::Station.should_receive(:from_xml).with(station.to_s)
42
42
  end
43
- IRail::NMBS::DocumentParser.parse_stations(xml_string)
43
+ IRail::NMBS::XMLParser.parse_stations(xml_string)
44
44
  end
45
45
 
46
46
  it "returns as many stations as in the xml payload" do
47
- IRail::NMBS::DocumentParser.parse_stations(xml_string).size.should eql stations.size
47
+ IRail::NMBS::XMLParser.parse_stations(xml_string).size.should eql stations.size
48
48
  end
49
49
  end
50
50
 
@@ -61,23 +61,23 @@ describe IRail::NMBS::DocumentParser do
61
61
 
62
62
  it "gets the xml payload from the string passed as parameter" do
63
63
  Nokogiri.should_receive(:XML).with(xml_string)
64
- IRail::NMBS::DocumentParser.parse_connections(xml_string)
64
+ IRail::NMBS::XMLParser.parse_connections(xml_string)
65
65
  end
66
66
 
67
67
  it "extracts the connections from the xml payload" do
68
- xml_payload.should_receive(:xpath).with(IRail::NMBS::DocumentParser::CONNECTION_XPATH)
69
- IRail::NMBS::DocumentParser.parse_connections(xml_string)
68
+ xml_payload.should_receive(:xpath).with(IRail::NMBS::XMLParser::CONNECTION_XPATH)
69
+ IRail::NMBS::XMLParser.parse_connections(xml_string)
70
70
  end
71
71
 
72
72
  it "creates a new connection for all parsed connection attributes" do
73
73
  connections.each do |connection|
74
74
  IRail::NMBS::Connection.should_receive(:from_xml).with(connection.to_s)
75
75
  end
76
- IRail::NMBS::DocumentParser.parse_connections(xml_string)
76
+ IRail::NMBS::XMLParser.parse_connections(xml_string)
77
77
  end
78
78
 
79
79
  it "returns as many connections as in the xml payload" do
80
- IRail::NMBS::DocumentParser.parse_connections(xml_string).size.should eql connections.size
80
+ IRail::NMBS::XMLParser.parse_connections(xml_string).size.should eql connections.size
81
81
  end
82
82
  end
83
83
 
@@ -95,21 +95,21 @@ describe IRail::NMBS::DocumentParser do
95
95
 
96
96
  it "gets the xml payload from the string passed as parameter" do
97
97
  Nokogiri.should_receive(:XML).with(xml_string)
98
- IRail::NMBS::DocumentParser.parse_vehicle(xml_string)
98
+ IRail::NMBS::XMLParser.parse_vehicle(xml_string)
99
99
  end
100
100
 
101
101
  it "extracts the vehicle from the xml payload" do
102
- xml_payload.should_receive(:xpath).with(IRail::NMBS::DocumentParser::VEHICLE_XPATH)
103
- IRail::NMBS::DocumentParser.parse_vehicle(xml_string)
102
+ xml_payload.should_receive(:xpath).with(IRail::NMBS::XMLParser::VEHICLE_XPATH)
103
+ IRail::NMBS::XMLParser.parse_vehicle(xml_string)
104
104
  end
105
105
 
106
106
  it "creates a new vehicle for the parsed vehicle attributes" do
107
107
  IRail::NMBS::VehicleInformation.should_receive(:from_xml).with(vehicle.to_s)
108
- IRail::NMBS::DocumentParser.parse_vehicle(xml_string)
108
+ IRail::NMBS::XMLParser.parse_vehicle(xml_string)
109
109
  end
110
110
 
111
111
  it "returns a vehicule instance" do
112
- IRail::NMBS::DocumentParser.parse_vehicle(xml_string).should eql vehicle_instance
112
+ IRail::NMBS::XMLParser.parse_vehicle(xml_string).should eql vehicle_instance
113
113
  end
114
114
  end
115
115
 
@@ -124,11 +124,11 @@ describe IRail::NMBS::DocumentParser do
124
124
 
125
125
  it "creates a liveboard from the xml payload" do
126
126
  IRail::NMBS::Liveboard.should_receive(:from_xml).with(xml_string)
127
- IRail::NMBS::DocumentParser.parse_liveboard(xml_string)
127
+ IRail::NMBS::XMLParser.parse_liveboard(xml_string)
128
128
  end
129
129
 
130
130
  it "returns a liveboard instance" do
131
- IRail::NMBS::DocumentParser.parse_liveboard(xml_string).should eql liveboard_instance
131
+ IRail::NMBS::XMLParser.parse_liveboard(xml_string).should eql liveboard_instance
132
132
  end
133
133
  end
134
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-irail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70221051588820 !ruby/object:Gem::Requirement
16
+ requirement: &70350038980380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70221051588820
24
+ version_requirements: *70350038980380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70221051588400 !ruby/object:Gem::Requirement
27
+ requirement: &70350038979960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70221051588400
35
+ version_requirements: *70350038979960
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: roxml
38
- requirement: &70221051587980 !ruby/object:Gem::Requirement
38
+ requirement: &70350038979540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70221051587980
46
+ version_requirements: *70350038979540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &70221051587560 !ruby/object:Gem::Requirement
49
+ requirement: &70350038979120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70221051587560
57
+ version_requirements: *70350038979120
58
58
  description: IRail makes Belgian railway schedule easily available for anyone. This
59
59
  is a Ruby wrapper for their API.
60
60
  email:
@@ -89,7 +89,7 @@ files:
89
89
  - lib/ruby-irail/packages/nmbs/models/vehicle.rb
90
90
  - lib/ruby-irail/packages/nmbs/models/vehicle_information.rb
91
91
  - lib/ruby-irail/packages/nmbs/models/vehicle_trip.rb
92
- - lib/ruby-irail/packages/nmbs/parser/document_parser.rb
92
+ - lib/ruby-irail/packages/nmbs/parser/xml_parser.rb
93
93
  - lib/version.rb
94
94
  - ruby-irail.gemspec
95
95
  - spec/http/request_spec.rb
@@ -109,7 +109,7 @@ files:
109
109
  - spec/packages/nmbs/models/vehicle_information_spec.rb
110
110
  - spec/packages/nmbs/models/vehicle_spec.rb
111
111
  - spec/packages/nmbs/models/vehicle_trip_spec.rb
112
- - spec/packages/nmbs/parser/document_parser_spec.rb
112
+ - spec/packages/nmbs/parser/xml_parser_spec.rb
113
113
  homepage: https://github.com/mlainez/ruby-irail
114
114
  licenses: []
115
115
  post_install_message:
@@ -152,4 +152,4 @@ test_files:
152
152
  - spec/packages/nmbs/models/vehicle_information_spec.rb
153
153
  - spec/packages/nmbs/models/vehicle_spec.rb
154
154
  - spec/packages/nmbs/models/vehicle_trip_spec.rb
155
- - spec/packages/nmbs/parser/document_parser_spec.rb
155
+ - spec/packages/nmbs/parser/xml_parser_spec.rb