Class: Graffle::Point

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/graffle/point.rb

Overview

An x,y coordinate relative to the origin of a Sheet.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Point

If two arguments, they are the x and y coordinates of the Point. Otherwise, the single argument is a string to be parsed to find the coordinates.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graffle/point.rb', line 18

def initialize(*args)
  if args.length == 2
    @x = args[0]; @y = args[1]
  elsif args[0] =~ /\{\{(.*),\s(.*)\}, \{.*,\s.*\}\}/
    initialize(Float($1), Float($2))
  elsif args[0] =~ /\{(.*),\s(.*)\}/
    initialize(Float($1), Float($2))
  else
    user_is_bewildered
  end
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



13
14
15
# File 'lib/graffle/point.rb', line 13

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



13
14
15
# File 'lib/graffle/point.rb', line 13

def y
  @y
end

Instance Method Details

#<=>(other) ⇒ Object

One Point is “less than” another if it starts higher than it on the page. If they start at the same height, the one furthest to the left is less.



35
36
37
38
# File 'lib/graffle/point.rb', line 35

def <=>(other)
  return self.x <=> other.x if self.y == other.y
  return self.y <=> other.y
end