Class: Origami::Rectangle

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

Overview

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

Constant Summary

Constants inherited from Array

Array::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes inherited from Array

#names_cache, #strings_cache, #xref_cache

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#+, #<<, #[]=, #copy, native_type, parse, #pre_build, #to_a, #to_obfuscated_str, #to_s

Methods included from Object

#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, parse, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Methods inherited from Array

#to_o

Constructor Details

#initialize(lowerleftx, lowerlefty, upperrightx, upperrighty) ⇒ Rectangle

Returns a new instance of Rectangle.



204
205
206
# File 'lib/origami/array.rb', line 204

def initialize(lowerleftx, lowerlefty, upperrightx, upperrighty)
  super([ lowerleftx, lowerlefty, upperrightx, upperrighty ])
end

Class Method Details

.[](coords) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/origami/array.rb', line 182

def [](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.values_at(:x).first || 0
      y = coords.values_at(:y).first || 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