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 = nil, coordinates = nil) ⇒ Polygon

Returns a new instance of Polygon.



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

def initialize(type = nil, coordinates = nil)
  @type = type
  @coordinates = coordinates
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

#typeType3Enum

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.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/verizon/models/polygon.rb', line 47

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 object from extracted values.
  Polygon.new(type,
              coordinates)
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.



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.type,
                            ->(val) { Type3Enum.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) { Type3Enum.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.



88
89
90
91
# File 'lib/verizon/models/polygon.rb', line 88

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

#to_sObject

Provides a human-readable string representation of the object.



82
83
84
85
# File 'lib/verizon/models/polygon.rb', line 82

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