Class: Response

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

Instance Method Summary collapse

Constructor Details

#initialize(resp) ⇒ Response



6
7
8
# File 'lib/response.rb', line 6

def initialize(resp)
  @resp = resp
end

Instance Method Details

#linhasObject



32
33
34
# File 'lib/response.rb', line 32

def linhas
  @resp.map{ |l| LinhaStrans.new(l) }
end

#model(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/response.rb', line 10

def model(path)
  @resp = JSON.parse(@resp.body)
  case path
  when :signin
    token
  when :linhas
    linhas
  when :veiculos
    veiculos
  when :veiculos_linha
    veiculos_linha
  when :paradas
    paradas
  when :paradas_linha
    paradas_linha
  end
end

#paradasObject



49
50
51
# File 'lib/response.rb', line 49

def paradas
  @resp.map{|p| ParadaStrans.new(p) }
end

#paradas_linhaObject



53
54
55
# File 'lib/response.rb', line 53

def paradas_linha
  @resp['Paradas'].map{|p| ParadaStrans.new(p) }
end

#tokenObject



28
29
30
# File 'lib/response.rb', line 28

def token
  @resp
end

#veiculosObject



36
37
38
39
40
41
42
# File 'lib/response.rb', line 36

def veiculos
  v = @resp.map do |node|
    linha = LinhaStrans.new(node['Linha'])
    linha.veiculos
  end
  v.reduce(:concat)
end

#veiculos_linhaObject



44
45
46
47
# File 'lib/response.rb', line 44

def veiculos_linha
  linha = LinhaStrans.new(@resp['Linha'])
  linha.veiculos
end