13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/transport_factory.rb', line 13
def self.create(json, resource)
if json['errors']
return Error.new json
else
case resource
when 'locations'
return json['stations'].map do |station|
Station.new station
end
when 'connections'
return json[resource].map do |connection|
Connection.new connection
end
when 'stationboard'
return json[resource].map do |journey|
Journey.new journey
end
else
raise ArgumentError.new('Unknown Resource: ', resource)
end
end
end
|