Class: Verizon::Polygon

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/verizon/models/polygon.rb

Overview

A Polygon is a type of geometry that represents a collection of points that form a closed ring. NOTE: This API only supports a single polygon in the Polygon geometry, so holes cannot be defines at this point. Support for hole will be added in future releases.

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(type:, coordinates:, additional_properties: nil) ⇒ Polygon

Returns a new instance of Polygon.



41
42
43
44
45
46
47
48
# File 'lib/verizon/models/polygon.rb', line 41

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

  @type = type
  @coordinates = coordinates
  @additional_properties = additional_properties
end

Instance Attribute Details

#coordinatesArray[Float]

TODO: Write general description for this method

Returns:

  • (Array[Float])


21
22
23
# File 'lib/verizon/models/polygon.rb', line 21

def coordinates
  @coordinates
end

#typePolygonType

TODO: Write general description for this method

Returns:



17
18
19
# File 'lib/verizon/models/polygon.rb', line 17

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/verizon/models/polygon.rb', line 51

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : nil
  coordinates = hash.key?('coordinates') ? hash['coordinates'] : 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.
  Polygon.new(type: type,
              coordinates: coordinates,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



24
25
26
27
28
29
# File 'lib/verizon/models/polygon.rb', line 24

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

.nullablesObject

An array for nullable fields



37
38
39
# File 'lib/verizon/models/polygon.rb', line 37

def self.nullables
  []
end

.optionalsObject

An array for optional fields



32
33
34
# File 'lib/verizon/models/polygon.rb', line 32

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Polygon | Hash)

    value against the validation is performed.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/verizon/models/polygon.rb', line 73

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.type,
                            ->(val) { PolygonType.validate(val) }) and
        APIHelper.valid_type?(value.coordinates,
                              ->(val) { val.instance_of? Float })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['type'],
                          ->(val) { PolygonType.validate(val) }) and
      APIHelper.valid_type?(value['coordinates'],
                            ->(val) { val.instance_of? Float })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



101
102
103
104
105
# File 'lib/verizon/models/polygon.rb', line 101

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

#to_sObject

Provides a human-readable string representation of the object.



94
95
96
97
98
# File 'lib/verizon/models/polygon.rb', line 94

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