Class: Verizon::GeoFeature

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

Overview

GeoFeature 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(type:, geometry:, properties:) ⇒ GeoFeature

Returns a new instance of GeoFeature.



43
44
45
46
47
# File 'lib/verizon/models/geo_feature.rb', line 43

def initialize(type:, geometry:, properties:)
  @type = type
  @geometry = geometry
  @properties = properties
end

Instance Attribute Details

#geometryObject

TODO: Write general description for this method

Returns:

  • (Object)


18
19
20
# File 'lib/verizon/models/geo_feature.rb', line 18

def geometry
  @geometry
end

#propertiesObject

TODO: Write general description for this method

Returns:

  • (Object)


22
23
24
# File 'lib/verizon/models/geo_feature.rb', line 22

def properties
  @properties
end

#typeFeatureType

TODO: Write general description for this method

Returns:



14
15
16
# File 'lib/verizon/models/geo_feature.rb', line 14

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/verizon/models/geo_feature.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : nil
  geometry = hash.key?('geometry') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Geometry), hash['geometry']
  ) : nil
  properties = hash.key?('properties') ? hash['properties'] : nil

  # Create object from extracted values.
  GeoFeature.new(type: type,
                 geometry: geometry,
                 properties: properties)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/verizon/models/geo_feature.rb', line 25

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

.nullablesObject

An array for nullable fields



39
40
41
# File 'lib/verizon/models/geo_feature.rb', line 39

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
# File 'lib/verizon/models/geo_feature.rb', line 34

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (GeoFeature | Hash)

    value against the validation is performed.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/verizon/models/geo_feature.rb', line 68

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.type,
                            ->(val) { FeatureType.validate(val) }) and
        UnionTypeLookUp.get(:Geometry)
                       .validate(value.geometry) and
        APIHelper.valid_type?(value.properties,
                              ->(val) { val.instance_of? Object })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['type'],
                          ->(val) { FeatureType.validate(val) }) and
      UnionTypeLookUp.get(:Geometry)
                     .validate(value['geometry']) and
      APIHelper.valid_type?(value['properties'],
                            ->(val) { val.instance_of? Object })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



99
100
101
102
103
# File 'lib/verizon/models/geo_feature.rb', line 99

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

#to_sObject

Provides a human-readable string representation of the object.



93
94
95
96
# File 'lib/verizon/models/geo_feature.rb', line 93

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