Class: TransfGov::State

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ State

Returns a new instance of State.



10
11
12
13
14
15
# File 'lib/transf_gov/state.rb', line 10

def initialize(attributes)
  @id = attributes["id"] 
  @sigla = attributes["sigla"]
  @regiao = attributes["regiao"]
  @nome = attributes["nome"]
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/transf_gov/state.rb', line 8

def id
  @id
end

#nomeObject (readonly)

Returns the value of attribute nome.



8
9
10
# File 'lib/transf_gov/state.rb', line 8

def nome
  @nome
end

#regiaoObject (readonly)

Returns the value of attribute regiao.



8
9
10
# File 'lib/transf_gov/state.rb', line 8

def regiao
  @regiao
end

#siglaObject (readonly)

Returns the value of attribute sigla.



8
9
10
# File 'lib/transf_gov/state.rb', line 8

def sigla
  @sigla
end

Class Method Details

.allObject



24
25
26
27
28
# File 'lib/transf_gov/state.rb', line 24

def self.all
  response = Faraday.get("#{STATE_ENDPOINT}")
  estados = JSON.parse(response.body)
  estados.map { |attributes| new(attributes) }
end

.find(id) ⇒ Object



17
18
19
20
21
22
# File 'lib/transf_gov/state.rb', line 17

def self.find(id)
  sigla = id.is_a?(Symbol) ? id.to_s.upcase : id.upcase
  response = Faraday.get("#{STATE_ENDPOINT}/#{sigla}")
  attributes = JSON.parse(response.body)
  new(attributes)
end

Instance Method Details

#citiesObject



30
31
32
33
34
# File 'lib/transf_gov/state.rb', line 30

def cities
  response = Faraday.get("#{STATE_ENDPOINT}/#{sigla}/municipios")
  municipios = JSON.parse(response.body)
  municipios.map { |attributes| TransfGov::City.new(attributes) }
end