Class: Origami::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/array.rb

Overview

Class representing a location on a page or a bounding box.

Class Method Summary collapse

Class Method Details

.[](coords) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/origami/array.rb', line 270

def self.[](coords)
    corners =
        if [ :llx, :lly, :urx, :ury ].all? {|p| coords.include?(p)}
            coords.values_at(:llx, :lly, :urx, :ury)
        elsif [ :width, :height ].all? {|p| coords.include?(p)}
            width, height = coords.values_at(:width, :height)
            x = coords.fetch(:x, 0)
            y = coords.fetch(:y, 0)
            [ x, y, x+width, y+height ]
        else
            raise ArgumentError, "Bad arguments for #{self.class}: #{coords.inspect}"
        end

    unless corners.all? { |corner| corner.is_a?(Numeric) }
        raise TypeError, "All coords must be numbers"
    end

    Rectangle.new(corners)
end