Class: IBGE::UF

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ UF

Returns a new instance of UF.



5
6
7
8
9
10
# File 'lib/ibge/uf.rb', line 5

def initialize(options = {})
  @id     = options['id']
  @nome   = options['nome']
  @sigla  = options['sigla']
  @regiao = Regiao.new(options['regiao'])
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ibge/uf.rb', line 3

def id
  @id
end

#nomeObject

Returns the value of attribute nome.



3
4
5
# File 'lib/ibge/uf.rb', line 3

def nome
  @nome
end

#regiaoObject

Returns the value of attribute regiao.



3
4
5
# File 'lib/ibge/uf.rb', line 3

def regiao
  @regiao
end

#siglaObject

Returns the value of attribute sigla.



3
4
5
# File 'lib/ibge/uf.rb', line 3

def sigla
  @sigla
end

Class Method Details

.obter_ufsObject

Obtém o conjunto de Unidades da Federação do Brasil.

Examples:

ufs = IBGE::UF.obter_ufs
ufs.first.class #=> IBGE::UF
ufs.first.nome #=> "Acre"
ufs.map(&:sigla) #=> ['AC', 'AM', 'AP'...]


19
20
21
22
23
# File 'lib/ibge/uf.rb', line 19

def self.obter_ufs
  resposta = RestClient.get("#{BASE_URL}/estados")

  tratar_retorno(resposta)
end

.ufs_por_identificador(ufs) ⇒ UF+

Obtém o conjunto de Unidades da Federação do Brasil a partir dos respectivos identificadores. Pode ser informada a sigla, identificador (ID) ou um array de siglas/identificadores.

Examples:

uf = IBGE::UF.uf_por_identificador('CE')

ufs = IBGE::UF.ufs_por_identificador(['BA', 'CE'])

Parameters:

  • ufs (String, Integer, Array)

Returns:



35
36
37
38
39
40
# File 'lib/ibge/uf.rb', line 35

def self.ufs_por_identificador(ufs)
  ufs      = IBGE.formatar(ufs)
  resposta = RestClient.get("#{BASE_URL}/estados/#{ufs}")

  tratar_retorno(resposta)
end

.ufs_por_regiao(regioes) ⇒ Array<UF>

Obtém o conjunto de Unidades da Federação do Brasil a partir dos identificadores das regiões. Pode ser informada a sigla, o identificador (ID) ou um array de siglas/identificadores.

Examples:

ufs = IBGE::UF.ufs_por_regiao('NE')
ufs.first.nome #=> "Maranhão"

ufs = IBGE::UF.ufs_por_regiao(['NE', 'N'])
ufs.map(&:nome) #=> ['Ceará', 'Amazonas'...]

Parameters:

  • regioes (String, Integer, Array)

Returns:

  • (Array<UF>)


54
55
56
57
58
59
# File 'lib/ibge/uf.rb', line 54

def self.ufs_por_regiao(regioes)
  regioes  = IBGE.formatar(regioes)
  resposta = RestClient.get("#{BASE_URL}/regioes/#{regioes}/estados")

  tratar_retorno(resposta)
end