Class: RubyVolt::Meta::Geography::Ring

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_volt/meta/geography.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points = []) ⇒ Ring

Returns a new instance of Ring.



59
60
61
62
# File 'lib/ruby_volt/meta/geography.rb', line 59

def initialize(points = [])
  @points = []
  points.each {|point| add_point(point)}
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



57
58
59
# File 'lib/ruby_volt/meta/geography.rb', line 57

def points
  @points
end

Instance Method Details

#==(other) ⇒ Object



98
99
100
# File 'lib/ruby_volt/meta/geography.rb', line 98

def ==(other)
  other.is_a?(Ring) && (points.size == other.points.size) && eval(points.map.with_index {|point, index| point == other.points[index]}.join("&&"))||true
end

#add_point(point) ⇒ Object

Raises:

  • (::ArgumentError)


64
65
66
67
# File 'lib/ruby_volt/meta/geography.rb', line 64

def add_point(point)
  raise(::ArgumentError, "Point has to be represented by a pseudo container RubyVolt::Meta::Geography::Point") unless point.is_a?(Point)
  @points << point unless @points.include?(point)
end

#close_pointsObject



86
87
88
# File 'lib/ruby_volt/meta/geography.rb', line 86

def close_points
  (points[-1] == points[0]) ? points : points + [points[0]]
end

#fork_reverse_pointsObject



73
74
75
# File 'lib/ruby_volt/meta/geography.rb', line 73

def fork_reverse_points
  Ring.new(reverse_points)
end

#inspectObject



69
70
71
# File 'lib/ruby_volt/meta/geography.rb', line 69

def inspect
  to_wkt
end

#reverse_pointsObject



82
83
84
# File 'lib/ruby_volt/meta/geography.rb', line 82

def reverse_points
  points[1..-1].reverse.prepend(points[0])
end

#reverse_points!Object



77
78
79
80
# File 'lib/ruby_volt/meta/geography.rb', line 77

def reverse_points!
  @points = reverse_points
  self
end

#to_sObject



90
91
92
# File 'lib/ruby_volt/meta/geography.rb', line 90

def to_s
  "(#{close_points.join(", ")})"
end

#to_wktObject



94
95
96
# File 'lib/ruby_volt/meta/geography.rb', line 94

def to_wkt
  "LINESTRING#{to_s}"
end