Class: Ruvi::Selection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = Point.new, e = Point.new, mode = nil) ⇒ Selection

Returns a new instance of Selection.



16
17
18
19
# File 'lib/selections.rb', line 16

def initialize s = Point.new, e = Point.new, mode = nil
    @mode = mode
    @s, @e = s, e
end

Instance Attribute Details

#eObject

Returns the value of attribute e.



14
15
16
# File 'lib/selections.rb', line 14

def e
  @e
end

#modeObject

Returns the value of attribute mode.



15
16
17
# File 'lib/selections.rb', line 15

def mode
  @mode
end

#sObject

Returns the value of attribute s.



14
15
16
# File 'lib/selections.rb', line 14

def s
  @s
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/selections.rb', line 20

def invalid?
    self.s.nil? || self.e.nil?
end

#reverseObject



23
24
25
26
27
28
29
# File 'lib/selections.rb', line 23

def reverse
    mydup = self.dup
    tmp = mydup.s
    mydup.s = mydup.e
    mydup.e = tmp
    mydup
end

#right_way_upObject



30
31
32
33
34
# File 'lib/selections.rb', line 30

def right_way_up
    raise "right_way_up called for selection with nil s" if @s.nil?
    raise "right_way_up called for selection with nil e" if @e.nil?
    (@e > @s) ? self : reverse
end