Class: RCAP::Base::Point

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/rcap/base/point.rb

Direct Known Subclasses

Circle, CAP_1_0::Point, CAP_1_1::Point, CAP_1_2::Point

Constant Summary

MAX_LONGITUDE =
180
MIN_LONGITUDE =
-180
MAX_LATTITUDE =
90
MIN_LATTITUDE =
-90
LATTITUDE_KEY =
'lattitude'
LONGITUDE_KEY =
'longitude'
LATTITUDE_INDEX =
0
LONGITUDE_INDEX =
1

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Point) initialize {|_self| ... }

A new instance of Point

Parameters:

  • attributes (Hash)

Yields:

  • (_self)

Yield Parameters:



23
24
25
# File 'lib/rcap/base/point.rb', line 23

def initialize
  yield( self ) if block_given?
end

Instance Attribute Details

- (Numeric) lattitude

Returns:

  • (Numeric)


12
13
14
# File 'lib/rcap/base/point.rb', line 12

def lattitude
  @lattitude
end

- (Numeric) longitude

Returns:

  • (Numeric)


14
15
16
# File 'lib/rcap/base/point.rb', line 14

def longitude
  @longitude
end

Class Method Details

+ (Point) from_a(point_array)

Parameters:

  • point_array (Array(Numeric, Numeric))

Returns:



79
80
81
82
83
84
# File 'lib/rcap/base/point.rb', line 79

def self.from_a( point_array )
  self.new do |point|
    point.lattitude = point_array[ LATTITUDE_INDEX ].to_f
    point.longitude = point_array[ LONGITUDE_INDEX ].to_f
  end
end

+ (Point) from_h(point_hash)

Parameters:

  • point_hash (Hash)

Returns:



59
60
61
62
63
64
# File 'lib/rcap/base/point.rb', line 59

def self.from_h( point_hash )
  self.new do |point|
    point.lattitude = point_hash[ LATTITUDE_KEY ].to_f
    point.longitude = point_hash[ LONGITUDE_KEY ].to_f
  end
end

Instance Method Details

- (true, false) ==(other)

Two points are equivalent if they have the same lattitude and longitude

Parameters:

Returns:

  • (true, false)


44
45
46
# File 'lib/rcap/base/point.rb', line 44

def ==( other )
  [ self.lattitude, self.longitude ] == [ other.lattitude, other.longitude ]
end

- (String) inspect

Returns:



36
37
38
# File 'lib/rcap/base/point.rb', line 36

def inspect
  '('+self.to_s+')'
end

- (Array(Numeric, Numeric)) to_a

Returns:

  • (Array(Numeric, Numeric))


70
71
72
73
74
75
# File 'lib/rcap/base/point.rb', line 70

def to_a
  Array.new.tap do |array|
    array[ LATTITUDE_INDEX ] = self.lattitude
    array[ LONGITUDE_INDEX ] = self.longitude
  end
end

- (Hash) to_h

Returns:

  • (Hash)


52
53
54
55
# File 'lib/rcap/base/point.rb', line 52

def to_h
  RCAP.attribute_values_to_hash( [ LATTITUDE_KEY, self.lattitude ],
                                 [ LONGITUDE_KEY, self.longitude ])
end

- (String) to_s

Returns a string representation of the point of the form

lattitude,longitude

Returns:



31
32
33
# File 'lib/rcap/base/point.rb', line 31

def to_s
  "#{ self.lattitude },#{ self.longitude }"
end