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

Instance Method Summary collapse

Class Method Details

.[](coords) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/origami/array.rb', line 210

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

Instance Method Details

#heightObject



234
235
236
# File 'lib/origami/array.rb', line 234

def height
  self[3] - self[1]
end

#widthObject



230
231
232
# File 'lib/origami/array.rb', line 230

def width
  self[2] - self[0]
end