Class: RubyVolt::Meta::Geography::Ring
- Inherits:
-
Object
- Object
- RubyVolt::Meta::Geography::Ring
- Defined in:
- lib/ruby_volt/meta/geography.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_point(point) ⇒ Object
- #close_points ⇒ Object
- #fork_reverse_points ⇒ Object
-
#initialize(points = []) ⇒ Ring
constructor
A new instance of Ring.
- #inspect ⇒ Object
- #reverse_points ⇒ Object
- #reverse_points! ⇒ Object
- #to_s ⇒ Object
- #to_wkt ⇒ Object
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
#points ⇒ Object (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
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_points ⇒ Object
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_points ⇒ Object
73 74 75 |
# File 'lib/ruby_volt/meta/geography.rb', line 73 def fork_reverse_points Ring.new(reverse_points) end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/ruby_volt/meta/geography.rb', line 69 def inspect to_wkt end |
#reverse_points ⇒ Object
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_s ⇒ Object
90 91 92 |
# File 'lib/ruby_volt/meta/geography.rb', line 90 def to_s "(#{close_points.join(", ")})" end |
#to_wkt ⇒ Object
94 95 96 |
# File 'lib/ruby_volt/meta/geography.rb', line 94 def to_wkt "LINESTRING#{to_s}" end |