Code Coverage
 
Lines
Covered
100.00% covered (success)
100.00%
48 / 48
1
module TheFox
1
module TermKit
##
# A single point on a x-y-grid.
1
class Point
1
attr_accessor :x
1
attr_accessor :y
1
def initialize(x = nil, y = nil)
6833
case x
when Array
350
y = x[1]
350
x = x[0]
when Hash
2
y = if x['y']
1
x['y']
elsif x[:y]
1
x[:y]
end
2
x = if x['x']
1
x['x']
elsif x[:x]
1
x[:x]
end
end
6833
@x = x
6833
@y = y
end
1
def ==(point)
# puts "Point == compare"
148
@x == point.x && @y == point.y
end
# def ===(point)
# puts "Point === compare"
# #@x == point.x && @y == point.y
# false
# end
# def eql?(point)
# puts "Point eql? compare"
# false
# end
1
def +(point)
395
x = nil
395
y = nil
395
if !@x.nil? || !point.x.nil?
394
x = @x.to_i + point.x.to_i
end
395
if !@y.nil? || !point.y.nil?
394
y = @y.to_i + point.y.to_i
end
395
self.class.new(x, y)
end
1
def -(point)
5
x = nil
5
y = nil
5
if !@x.nil? || !point.x.nil?
4
x = @x.to_i - point.x.to_i
end
5
if !@y.nil? || !point.y.nil?
4
y = @y.to_i - point.y.to_i
end
5
self.class.new(x, y)
end
1
def to_s
526
"#{@x}:#{@y}"
end
1
def to_a
3736
[@x, @y]
end
1
def inspect
4
x_s = x.nil? ? 'NIL' : x
4
y_s = y.nil? ? 'NIL' : y
4
"#<Point x=#{x_s} y=#{y_s}>"
end
1
def missing_function
end
1
def self.from_s(s)
206
x, y =
s
.split(/[:,]/, 2)
.map{ |pos|
412
pos.nil? || pos == '' ? nil : pos.to_i
}
206
new(x, y)
end
end
end
end