Module: Graffle::Container

Included in:
Group, Sheet
Defined in:
lib/graffle/stereotypes.rb

Overview

Behavior common to Sheet and Group, both of which contain an array of AbstractGraphic. :stopdoc: MISSING: perhaps some cleverness with Enumerator would be in order? :startdoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.stereotype_children_of(parent) ⇒ Object

:nodoc:



429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/graffle/stereotypes.rb', line 429

def self.stereotype_children_of(parent) # :nodoc:
  parent.graphics.each do | child |
    if Graffle.stereotype(child)
      child.container = parent
    else
      puts "Can not yet stereotype child with id #{child['ID'].inspect} and class #{child['Class'].inspect}."
      puts "Most likely there's been no call for it yet. So call for it."
      pp child.keys
    end
  end
  true
end

Instance Method Details

#delete_graphic(graphic) ⇒ Object

Delete a graphic from inside this Container The name is delete_graphic to avoid overriding the delete method on the underlying class.



396
397
398
399
# File 'lib/graffle/stereotypes.rb', line 396

def delete_graphic(graphic)
  graphic.container = nil
  graphics.delete(graphic)
end

#find_by_content(string) ⇒ Object

Find a graphic whose ShapedGraphic#content matches the given string.



422
423
424
425
426
427
# File 'lib/graffle/stereotypes.rb', line 422

def find_by_content(string)
  result = graphics.find do | elt |
    elt.respond_to?(:content) && 
      elt.content.as_plain_text.downcase === string.downcase
  end
end

#find_by_id(id) ⇒ Object

Find the AbstractGraphic matching the integer id. Returns nil if not found.

Mostly for internal use.



407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/graffle/stereotypes.rb', line 407

def find_by_id(id)
  result = graphics.find { | elt | elt.graffle_id == id }
  unless result
    return nil unless respond_to?(:container) # at the top of the tree.
    return nil unless container  # A null container should only happen 
                                 # in tests. Consider a test that 
                                 # uses find_by_id on a group, but the 
                                 # group is not contained in a sheet.
    result = container.find_by_id(id)
  end
  result
end

#with(*objects) ⇒ Object

:nodoc:



386
387
388
389
390
391
# File 'lib/graffle/stereotypes.rb', line 386

def with(*objects) # :nodoc: 
  objects.each do | o |
    self.graphics << o
    o.container = self  # works because instance_evaled.
  end
end