Class: GoogleMapsPlatform::PlaceAutocompleteStructuredFormat

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

Overview

PlaceAutocompleteStructuredFormat 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(main_text:, main_text_matched_substrings:, secondary_text: SKIP, secondary_text_matched_substrings: SKIP, additional_properties: nil) ⇒ PlaceAutocompleteStructuredFormat

Returns a new instance of PlaceAutocompleteStructuredFormat.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 57

def initialize(main_text:, main_text_matched_substrings:,
               secondary_text: SKIP,
               secondary_text_matched_substrings: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance

  additional_properties = {} if additional_properties.nil?

  @main_text = main_text
  @main_text_matched_substrings = main_text_matched_substrings
  @secondary_text = secondary_text unless secondary_text == SKIP
  unless secondary_text_matched_substrings == SKIP
    @secondary_text_matched_substrings =
      secondary_text_matched_substrings
  end
  @additional_properties = additional_properties
end

Instance Attribute Details

#main_textString

Contains the main text of a prediction, usually the name of the place.

Returns:

  • (String)


14
15
16
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 14

def main_text
  @main_text
end

#main_text_matched_substringsArray[PlaceAutocompleteMatchedSubstring]

Contains an array with offset value and length. These describe the location of the entered term in the prediction result text, so that the term can be highlighted if desired.



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

def main_text_matched_substrings
  @main_text_matched_substrings
end

#secondary_textString

Contains the secondary text of a prediction, usually the location of the place.

Returns:

  • (String)


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

def secondary_text
  @secondary_text
end

#secondary_text_matched_substringsArray[PlaceAutocompleteMatchedSubstring]

Contains an array with offset value and length. These describe the location of the entered term in the prediction result text, so that the term can be highlighted if desired.



31
32
33
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 31

def secondary_text_matched_substrings
  @secondary_text_matched_substrings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  main_text = hash.key?('main_text') ? hash['main_text'] : nil
  # Parameter is an array, so we need to iterate through it

  main_text_matched_substrings = nil
  unless hash['main_text_matched_substrings'].nil?
    main_text_matched_substrings = []
    hash['main_text_matched_substrings'].each do |structure|
      main_text_matched_substrings << (PlaceAutocompleteMatchedSubstring.from_hash(structure) if structure)
    end
  end

  main_text_matched_substrings = nil unless hash.key?('main_text_matched_substrings')
  secondary_text =
    hash.key?('secondary_text') ? hash['secondary_text'] : SKIP
  # Parameter is an array, so we need to iterate through it

  secondary_text_matched_substrings = nil
  unless hash['secondary_text_matched_substrings'].nil?
    secondary_text_matched_substrings = []
    hash['secondary_text_matched_substrings'].each do |structure|
      secondary_text_matched_substrings << (PlaceAutocompleteMatchedSubstring.from_hash(structure) if structure)
    end
  end

  secondary_text_matched_substrings = SKIP unless hash.key?('secondary_text_matched_substrings')

  # 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.

  PlaceAutocompleteStructuredFormat.new(main_text: main_text,
                                        main_text_matched_substrings: main_text_matched_substrings,
                                        secondary_text: secondary_text,
                                        secondary_text_matched_substrings: secondary_text_matched_substrings,
                                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['main_text'] = 'main_text'
  @_hash['main_text_matched_substrings'] = 'main_text_matched_substrings'
  @_hash['secondary_text'] = 'secondary_text'
  @_hash['secondary_text_matched_substrings'] =
    'secondary_text_matched_substrings'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
50
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 45

def self.optionals
  %w[
    secondary_text
    secondary_text_matched_substrings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



128
129
130
131
132
133
134
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 128

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

#to_sObject

Provides a human-readable string representation of the object.



119
120
121
122
123
124
125
# File 'lib/google_maps_platform/models/place_autocomplete_structured_format.rb', line 119

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