Class: ShellEv::Address

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/shell_ev/models/address.rb

Overview

Address of the Shell Recharge Location

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(street_and_number = SKIP, postal_code = SKIP, city = SKIP, country = SKIP) ⇒ Address

Returns a new instance of Address.



53
54
55
56
57
58
59
# File 'lib/shell_ev/models/address.rb', line 53

def initialize(street_and_number = SKIP, postal_code = SKIP, city = SKIP,
               country = SKIP)
  @street_and_number = street_and_number unless street_and_number == SKIP
  @postal_code = postal_code unless postal_code == SKIP
  @city = city unless city == SKIP
  @country = country unless country == SKIP
end

Instance Attribute Details

#cityString

City name of the Shell Recharge Location

Returns:

  • (String)


22
23
24
# File 'lib/shell_ev/models/address.rb', line 22

def city
  @city
end

#countryString

ISO 3166 Alpha-2 Country Code of the Shell Recharge Location

Returns:

  • (String)


26
27
28
# File 'lib/shell_ev/models/address.rb', line 26

def country
  @country
end

#postal_codeString

Postal Code of the Shell Recharge Location

Returns:

  • (String)


18
19
20
# File 'lib/shell_ev/models/address.rb', line 18

def postal_code
  @postal_code
end

#street_and_numberString

Street Name and Number of the Shell Recharge Location

Returns:

  • (String)


14
15
16
# File 'lib/shell_ev/models/address.rb', line 14

def street_and_number
  @street_and_number
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/shell_ev/models/address.rb', line 62

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  street_and_number =
    hash.key?('streetAndNumber') ? hash['streetAndNumber'] : SKIP
  postal_code = hash.key?('postalCode') ? hash['postalCode'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  country = hash.key?('country') ? hash['country'] : SKIP

  # Create object from extracted values.
  Address.new(street_and_number,
              postal_code,
              city,
              country)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
36
# File 'lib/shell_ev/models/address.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['street_and_number'] = 'streetAndNumber'
  @_hash['postal_code'] = 'postalCode'
  @_hash['city'] = 'city'
  @_hash['country'] = 'country'
  @_hash
end

.nullablesObject

An array for nullable fields



49
50
51
# File 'lib/shell_ev/models/address.rb', line 49

def self.nullables
  []
end

.optionalsObject

An array for optional fields



39
40
41
42
43
44
45
46
# File 'lib/shell_ev/models/address.rb', line 39

def self.optionals
  %w[
    street_and_number
    postal_code
    city
    country
  ]
end