Class: GoogleMapsPlatform::AddressComponent

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/address_component.rb

Overview

AddressComponent Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(long_name:, short_name:, types:, additional_properties: nil) ⇒ AddressComponent

Returns a new instance of AddressComponent.



50
51
52
53
54
55
56
57
58
# File 'lib/google_maps_platform/models/address_component.rb', line 50

def initialize(long_name:, short_name:, types:, additional_properties: nil)
  # Add additional model properties to the instance

  additional_properties = {} if additional_properties.nil?

  @long_name = long_name
  @short_name = short_name
  @types = types
  @additional_properties = additional_properties
end

Instance Attribute Details

#long_nameString

The full text description or name of the address component as returned by the Geocoder.

Returns:

  • (String)


15
16
17
# File 'lib/google_maps_platform/models/address_component.rb', line 15

def long_name
  @long_name
end

#short_nameString

An abbreviated textual name for the address component, if available. For example, an address component for the state of Alaska may have a long_name of “Alaska” and a short_name of “AK” using the 2-letter postal abbreviation.

Returns:

  • (String)


22
23
24
# File 'lib/google_maps_platform/models/address_component.rb', line 22

def short_name
  @short_name
end

#typesArray[String]

An array indicating the type of the address component. See the list of [supported types](developers.google.com/maps/documentation/places/web-service /supported_types).

Returns:

  • (Array[String])


29
30
31
# File 'lib/google_maps_platform/models/address_component.rb', line 29

def types
  @types
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/google_maps_platform/models/address_component.rb', line 61

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  long_name = hash.key?('long_name') ? hash['long_name'] : nil
  short_name = hash.key?('short_name') ? hash['short_name'] : nil
  types = hash.key?('types') ? hash['types'] : nil

  # Create a new hash for additional properties, removing known properties.

  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.

  AddressComponent.new(long_name: long_name,
                       short_name: short_name,
                       types: types,
                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



32
33
34
35
36
37
38
# File 'lib/google_maps_platform/models/address_component.rb', line 32

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['long_name'] = 'long_name'
  @_hash['short_name'] = 'short_name'
  @_hash['types'] = 'types'
  @_hash
end

.nullablesObject

An array for nullable fields



46
47
48
# File 'lib/google_maps_platform/models/address_component.rb', line 46

def self.nullables
  []
end

.optionalsObject

An array for optional fields



41
42
43
# File 'lib/google_maps_platform/models/address_component.rb', line 41

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



91
92
93
94
95
# File 'lib/google_maps_platform/models/address_component.rb', line 91

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} long_name: #{@long_name.inspect}, short_name: #{@short_name.inspect},"\
  " types: #{@types.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



84
85
86
87
88
# File 'lib/google_maps_platform/models/address_component.rb', line 84

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} long_name: #{@long_name}, short_name: #{@short_name}, types: #{@types},"\
  " additional_properties: #{@additional_properties}>"
end