Class: Response
- Inherits:
-
Object
- Object
- Response
- Defined in:
- lib/response.rb
Instance Method Summary collapse
-
#initialize(resp) ⇒ Response
constructor
A new instance of Response.
- #linhas ⇒ Object
- #model(path) ⇒ Object
- #paradas ⇒ Object
- #paradas_linha ⇒ Object
- #token ⇒ Object
- #veiculos ⇒ Object
- #veiculos_linha ⇒ Object
Constructor Details
#initialize(resp) ⇒ Response
6 7 8 |
# File 'lib/response.rb', line 6 def initialize(resp) @resp = resp end |
Instance Method Details
#linhas ⇒ Object
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 |
#paradas ⇒ Object
49 50 51 |
# File 'lib/response.rb', line 49 def paradas @resp.map{|p| ParadaStrans.new(p) } end |
#paradas_linha ⇒ Object
53 54 55 |
# File 'lib/response.rb', line 53 def paradas_linha @resp['Paradas'].map{|p| ParadaStrans.new(p) } end |
#token ⇒ Object
28 29 30 |
# File 'lib/response.rb', line 28 def token @resp end |
#veiculos ⇒ Object
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_linha ⇒ Object
44 45 46 47 |
# File 'lib/response.rb', line 44 def veiculos_linha linha = LinhaStrans.new(@resp['Linha']) linha.veiculos end |