Class: TransfGov::State
- Inherits:
-
Object
- Object
- TransfGov::State
- Defined in:
- lib/transf_gov/state.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#nome ⇒ Object
readonly
Returns the value of attribute nome.
-
#regiao ⇒ Object
readonly
Returns the value of attribute regiao.
-
#sigla ⇒ Object
readonly
Returns the value of attribute sigla.
Class Method Summary collapse
Instance Method Summary collapse
- #cities ⇒ Object
-
#initialize(attributes) ⇒ State
constructor
A new instance of State.
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/transf_gov/state.rb', line 8 def id @id end |
#nome ⇒ Object (readonly)
Returns the value of attribute nome.
8 9 10 |
# File 'lib/transf_gov/state.rb', line 8 def nome @nome end |
#regiao ⇒ Object (readonly)
Returns the value of attribute regiao.
8 9 10 |
# File 'lib/transf_gov/state.rb', line 8 def regiao @regiao end |
#sigla ⇒ Object (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
.all ⇒ Object
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
#cities ⇒ Object
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 |