Class: Spritpreisrechner::Region

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region) ⇒ Region

Returns a new instance of Region.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spritpreisrechner/region.rb', line 5

def initialize(region)
  @code = region[:code]
  @type = region[:type]
  @name = region[:name]
  @sub_regions = []

  region[:subRegions].each do |sub_region|
    @sub_regions << Region.new(sub_region)
  end

  @postal_codes = region[:postalCodes]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/spritpreisrechner/region.rb', line 3

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/spritpreisrechner/region.rb', line 3

def name
  @name
end

#postal_codesObject (readonly)

Returns the value of attribute postal_codes.



3
4
5
# File 'lib/spritpreisrechner/region.rb', line 3

def postal_codes
  @postal_codes
end

#sub_regionsObject (readonly)

Returns the value of attribute sub_regions.



3
4
5
# File 'lib/spritpreisrechner/region.rb', line 3

def sub_regions
  @sub_regions
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/spritpreisrechner/region.rb', line 3

def type
  @type
end

Class Method Details

.allObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/spritpreisrechner/region.rb', line 18

def self.all
  response = conn.get('regions')
  attributes = JSON.parse(response.body, symbolize_names: true)

  regions = []

  attributes.each do |region|
    regions << Region.new(region)
  end

  regions
end

.connObject



35
36
37
# File 'lib/spritpreisrechner/region.rb', line 35

def self.conn
  Spritpreisrechner.conn
end

.find(code) ⇒ Object



31
32
33
# File 'lib/spritpreisrechner/region.rb', line 31

def self.find(code)
  all.select { |r| r.code == code }.first
end