Class: Transport::TransportFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/transport_factory.rb

Class Method Summary collapse

Class Method Details

.create(json) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/transport_factory.rb', line 14

def self.create(json)
  json.each do |type, data|
    case type
      when 'stations'
        return data.map do |station|
          Location.new station
        end
      when 'connections'
        return data.map do |connection|
          Connection.new connection
        end
      when 'station'
        next
      when 'stationboard'
        return data.map do |journey|
          Journey.new journey
        end
      when 'errors'
        return data.map do |error|
          Error.new error
        end
      else
        raise ArgumentError.new('Unknown Type: ' + type)
    end
  end
end