Code Coverage
 
Lines
Covered
100.00% covered (success)
100.00%
61 / 61
1
module TheFox
1
module TermKit
##
# A composition of the Point class (`@origin` attribute) and the Size class (`@size` attribute).
1
class Rect
# Point instance.
1
attr_reader :origin
# Size instance.
1
attr_reader :size
1
attr_reader :x_range
1
attr_reader :y_range
1
def initialize(x = nil, y = nil, width = nil, height = nil)
139
@origin = Point.new(x, y)
139
@size = Size.new(width, height)
139
set_x_range
139
set_y_range
end
1
def origin=(origin)
118
@origin = origin
118
set_x_range
118
set_y_range
end
1
def size=(size)
24
@size = size
24
set_x_range
24
set_y_range
end
1
def x
515
@origin.x
end
1
def x_max
531
if !@origin.x.nil? && !@size.width.nil?
389
@origin.x + @size.width - 1
else
142
-1
end
end
1
def y
146
@origin.y
end
1
def y_max
388
if !@origin.y.nil? && !@size.height.nil?
258
@origin.y + @size.height - 1
else
130
-1
end
end
1
def width
52
@size.width
end
1
def height
50
@size.height
end
1
def has_default_values?
40
@origin.x.nil? && @origin.y.nil? && @size.width.nil? && @size.height.nil?
end
1
def to_points
80
points = []
80
@x_range.each do |x_pos|
248
@y_range.each do |y_pos|
428
points << Point.new(x_pos, y_pos)
end
end
80
points
end
1
def to_s
5
x_s = x.nil? ? 'NIL' : x
5
y_s = y.nil? ? 'NIL' : y
5
w_s = width.nil? ? 'NIL' : width
5
h_s = height.nil? ? 'NIL' : height
5
"#{x_s}:#{y_s}[#{w_s}:#{h_s}]"
end
1
def inspect
5
x_s = x.nil? ? 'NIL' : x
5
y_s = y.nil? ? 'NIL' : y
5
w_s = width.nil? ? 'NIL' : width
5
h_s = height.nil? ? 'NIL' : height
5
"#<Rect x=#{x_s} y=#{y_s} w=#{w_s} h=#{h_s}>"
end
1
private
1
def set_x_range
281
@x_range = Range.new(@origin.x.nil? ? 0: @origin.x, x_max)
end
1
def set_y_range
281
@y_range = Range.new(@origin.y.nil? ? 0: @origin.y, y_max)
end
end
end
end