Class: GoogleMapsPlatform::PlusCode

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

Overview

An encoded location reference, derived from latitude and longitude coordinates, that represents an area, 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named).

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(global_code:, compound_code: SKIP, additional_properties: nil) ⇒ PlusCode

Returns a new instance of PlusCode.



47
48
49
50
51
52
53
54
55
# File 'lib/google_maps_platform/models/plus_code.rb', line 47

def initialize(global_code:, compound_code: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @compound_code = compound_code unless compound_code == SKIP
  @global_code = global_code
  @additional_properties = additional_properties
end

Instance Attribute Details

#compound_codeString

The compound_code is a 6 character or longer local code with an explicit location (‘CWC8+R9, Mountain View, CA, USA`). Some APIs may return an empty string if the compound_code is not available.

Returns:

  • (String)


20
21
22
# File 'lib/google_maps_platform/models/plus_code.rb', line 20

def compound_code
  @compound_code
end

#global_codeString

The global_code is a 4 character area code and 6 character or longer local code (‘849VCWC8+R9`).

Returns:

  • (String)


25
26
27
# File 'lib/google_maps_platform/models/plus_code.rb', line 25

def global_code
  @global_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/google_maps_platform/models/plus_code.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  global_code = hash.key?('global_code') ? hash['global_code'] : nil
  compound_code = hash.key?('compound_code') ? hash['compound_code'] : SKIP

  # 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.
  PlusCode.new(global_code: global_code,
               compound_code: compound_code,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



28
29
30
31
32
33
# File 'lib/google_maps_platform/models/plus_code.rb', line 28

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['compound_code'] = 'compound_code'
  @_hash['global_code'] = 'global_code'
  @_hash
end

.nullablesObject

An array for nullable fields



43
44
45
# File 'lib/google_maps_platform/models/plus_code.rb', line 43

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
# File 'lib/google_maps_platform/models/plus_code.rb', line 36

def self.optionals
  %w[
    compound_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



86
87
88
89
90
# File 'lib/google_maps_platform/models/plus_code.rb', line 86

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

#to_sObject

Provides a human-readable string representation of the object.



79
80
81
82
83
# File 'lib/google_maps_platform/models/plus_code.rb', line 79

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