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 collapse

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

Methods included from Validation

#errors, included, #valid?, #validate

Constructor Details

#initialize {|_self| ... } ⇒ Point

Returns a new instance of Point.

Parameters:

  • attributes (Hash)

Yields:

  • (_self)

Yield Parameters:



25
26
27
# File 'lib/rcap/base/point.rb', line 25

def initialize
  yield(self) if block_given?
end

Instance Attribute Details

#lattitudeNumeric

Returns:

  • (Numeric)


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

def lattitude
  @lattitude
end

#longitudeNumeric

Returns:

  • (Numeric)


16
17
18
# File 'lib/rcap/base/point.rb', line 16

def longitude
  @longitude
end

Class Method Details

.from_a(point_array) ⇒ Point

Parameters:

  • point_array (Array(Numeric, Numeric))

Returns:



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

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

.from_h(point_hash) ⇒ Point

Parameters:

  • point_hash (Hash)

Returns:



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

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

Instance Method Details

#==(other) ⇒ true, false

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

Parameters:

Returns:

  • (true, false)


46
47
48
# File 'lib/rcap/base/point.rb', line 46

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

#inspectString

Returns:



38
39
40
# File 'lib/rcap/base/point.rb', line 38

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

#to_aArray(Numeric, Numeric)

Returns:

  • (Array(Numeric, Numeric))


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

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

#to_hHash

Returns:

  • (Hash)


54
55
56
57
# File 'lib/rcap/base/point.rb', line 54

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

#to_sString

Returns a string representation of the point of the form

lattitude,longitude

Returns:



33
34
35
# File 'lib/rcap/base/point.rb', line 33

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