Class: Verizon::Position

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

Overview

It provides a precise location in the WGS-84 coordinate system, from which short offsets may be used to create additional data using a flat earth projection centered on this location.

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(lat:, long:) ⇒ Position

Returns a new instance of Position.



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

def initialize(lat:, long:)
  @lat = lat
  @long = long
end

Instance Attribute Details

#latInteger

The geographic latitude of an object, expressed in 1/10th integer microdegrees, as a 31 bit value, and with reference to the horizontal datum then in use. The value 900000001 shall be used when unavailable.

Returns:

  • (Integer)


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

def lat
  @lat
end

#longInteger

The geographic longitude of an object, expressed in 1/10th integer microdegrees, as a 32-bit value, and with reference to the horizontal datum then in use. The value 1800000001 shall be used when unavailable.

Returns:

  • (Integer)


24
25
26
# File 'lib/verizon/models/position.rb', line 24

def long
  @long
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
# File 'lib/verizon/models/position.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  lat = hash.key?('lat') ? hash['lat'] : nil
  long = hash.key?('long') ? hash['long'] : nil

  # Create object from extracted values.
  Position.new(lat: lat,
               long: long)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
# File 'lib/verizon/models/position.rb', line 27

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

.nullablesObject

An array for nullable fields



40
41
42
# File 'lib/verizon/models/position.rb', line 40

def self.nullables
  []
end

.optionalsObject

An array for optional fields



35
36
37
# File 'lib/verizon/models/position.rb', line 35

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Position | Hash)

    value against the validation is performed.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/verizon/models/position.rb', line 64

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.lat,
                            ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.long,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['lat'],
                          ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['long'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



91
92
93
94
# File 'lib/verizon/models/position.rb', line 91

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

#to_sObject

Provides a human-readable string representation of the object.



85
86
87
88
# File 'lib/verizon/models/position.rb', line 85

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