Class: DYI::Drawing::Clipping

Inherits:
Element
  • Object
show all
Defined in:
lib/dyi/drawing/clipping.rb

Overview

Since:

  • 0.0.0

Constant Summary collapse

RULES =

Since:

  • 0.0.0

['nonzero', 'evenodd']

Constants inherited from Element

Element::ID_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Element

#description, #title

Instance Method Summary collapse

Methods inherited from Element

#has_uri_reference?, #id, #id=, #include_external_file?, #inner_id

Constructor Details

#initialize(*shapes) ⇒ Clipping

Returns a new instance of Clipping.

Since:

  • 0.0.0



34
35
36
37
# File 'lib/dyi/drawing/clipping.rb', line 34

def initialize(*shapes)
  @shapes = shapes
  @rules = Array.new(shapes.size)
end

Instance Attribute Details

#canvasObject (readonly)

Since:

  • 1.0.0



32
33
34
# File 'lib/dyi/drawing/clipping.rb', line 32

def canvas
  @canvas
end

#ruleObject (readonly)

Since:

  • 0.0.0



29
30
31
# File 'lib/dyi/drawing/clipping.rb', line 29

def rule
  @rule
end

#shapesObject (readonly)

Since:

  • 0.0.0



29
30
31
# File 'lib/dyi/drawing/clipping.rb', line 29

def shapes
  @shapes
end

Instance Method Details

#add_shape(shape, rule = nil) ⇒ Object

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



53
54
55
56
57
58
59
# File 'lib/dyi/drawing/clipping.rb', line 53

def add_shape(shape, rule=nil)
  raise ArgumentError, "\"#{rule}\" is invalid rule" if rule && !RULES.include?(rule)
  unless @shapes.include?(shape)
    @shapes.push(shape)
    @rules.push(rule)
  end
end

#child_elementsObject

Since:

  • 1.0.0



40
41
42
# File 'lib/dyi/drawing/clipping.rb', line 40

def child_elements
  @shapes
end

#each_shapesObject

:yields: shape, rule

Since:

  • 0.0.0



69
70
71
72
73
# File 'lib/dyi/drawing/clipping.rb', line 69

def each_shapes #:yields: shape, rule
  @shapes.size.times do |i|
    yield @shapes[i], @rules[i]
  end
end

#remove_shape(shape) ⇒ Object

Since:

  • 0.0.0



61
62
63
64
65
66
67
# File 'lib/dyi/drawing/clipping.rb', line 61

def remove_shape(shape)
  index = @shapes.each_with_index {|s, i| break i if s == shape}
  if index
    @shapes.delete_at(index)
    @rules.delete_at(index)
  end
end

#set_canvas(canvas) ⇒ Object

Since:

  • 1.0.0



45
46
47
48
49
50
51
# File 'lib/dyi/drawing/clipping.rb', line 45

def set_canvas(canvas)
  if @canvas.nil?
    @canvas = canvas
  elsif @canvas != canvas
    raise Arguments, "the clipping is registered to another canvas"
  end
end

#write_as(formatter, io = $>) ⇒ Object

Since:

  • 0.0.0



75
76
77
# File 'lib/dyi/drawing/clipping.rb', line 75

def write_as(formatter, io=$>)
  formatter.write_clipping(self, io)
end