Class: Spritpreisrechner::Region
- Inherits:
-
Object
- Object
- Spritpreisrechner::Region
- Defined in:
- lib/spritpreisrechner/region.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#postal_codes ⇒ Object
readonly
Returns the value of attribute postal_codes.
-
#sub_regions ⇒ Object
readonly
Returns the value of attribute sub_regions.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(region) ⇒ Region
constructor
A new instance of Region.
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/spritpreisrechner/region.rb', line 3 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/spritpreisrechner/region.rb', line 3 def name @name end |
#postal_codes ⇒ Object (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_regions ⇒ Object (readonly)
Returns the value of attribute sub_regions.
3 4 5 |
# File 'lib/spritpreisrechner/region.rb', line 3 def sub_regions @sub_regions end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/spritpreisrechner/region.rb', line 3 def type @type end |
Class Method Details
.all ⇒ Object
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 |
.conn ⇒ Object
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 |