Module: Graffle::LineGraphic

Includes:
AbstractGraphic, Builders
Defined in:
lib/graffle/stereotypes.rb,
lib/graphical_tests_for_rails/stereotype-extensions.rb

Overview

A line, be it straight, curved, or jagged. Lines can be connected to other objects. Even if there’s no arrowhead on the line, it still has a notion of a head and tail. (Alternate notation: it goes from one, to the other). The head or tail can be nil.

Instance Attribute Summary

Attributes included from AbstractGraphic

#container

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Builders

#abstract_graphic, #annotation, classed, #document, #group, #line_graphic, #line_label, raw, #shaped_graphic, #sheet, #text

Methods included from AbstractGraphic

#any_content_lines, #any_note_lines, #before?, #delete_yourself, graffle_class_matches?, #graffle_id, #graffle_id_is, #has_any_content?, #has_any_note?, #has_line_label_content?, #has_line_label_note?, #has_line_note?, #has_note?, #has_shaped_graphic_content?, #has_shaped_graphic_note?, #is_labeled_line?, #is_line_label?, #notes, #with_notes

Class Method Details

.takes_on(o) ⇒ Object

:nodoc:



292
293
294
# File 'lib/graffle/stereotypes.rb', line 292

def self.takes_on(o)   # :nodoc: 
  AbstractGraphic.takes_on(o, self)
end

Instance Method Details

#fromObject Also known as: tail

The AbstractGraphic the line comes from.



298
# File 'lib/graffle/stereotypes.rb', line 298

def from; ('Tail'); end

#has_label?Boolean

true if the line has a label. false otherwise.

Returns:

  • (Boolean)


317
318
319
# File 'lib/graffle/stereotypes.rb', line 317

def has_label?
  not (not label)  # Here is a gesture in honor of Scheme.
end

#labelObject

The label attached to a line. In the document, the label is a ShapedGraphic in the same Container as its line. The label points to the line, not the reverse. This method, though, pretends the line points to the label and returns it (or nil if there is no label).



310
311
312
313
314
# File 'lib/graffle/stereotypes.rb', line 310

def label
  container.graphics.find do |g|
    g.respond_to?(:line_id) && g.line_id == self.graffle_id
  end
end

#label_linesObject

A quick way to get the lines from a text’s label (as plain text). If the line doesn’t have a label, label_lines returns the empty array.



347
348
349
350
351
352
353
# File 'lib/graffle/stereotypes.rb', line 347

def label_lines
  if label
    label.content.as_lines
  else
    label || []    # TODO: Remove unnecessary first condition.
  end
end

#label_rtfObject

Almost certainly, what you care about is the Text of the label, which you could get like this:

line.label.content

This method is shorthand for that.



325
326
327
# File 'lib/graffle/stereotypes.rb', line 325

def label_rtf
  label.content
end

#line_label_content_linesObject

:nodoc # can be called by generated code



100
101
102
# File 'lib/graphical_tests_for_rails/stereotype-extensions.rb', line 100

def line_label_content_lines # :nodoc     # can be called by generated code
  label.content.as_lines
end

#line_label_note_linesObject

:nodoc: # can be called by generated code



104
105
106
# File 'lib/graphical_tests_for_rails/stereotype-extensions.rb', line 104

def line_label_note_lines # :nodoc:       # can be called by generated code
  label.note.as_lines
end

#line_note_linesObject

:nodoc: # can be called by generated code



96
97
98
# File 'lib/graphical_tests_for_rails/stereotype-extensions.rb', line 96

def line_note_lines # :nodoc:       # can be called by generated code
  note.as_lines
end

#originObject

The origin of the LineGraphic is the first Point in the points array. That’s the place the mouse pointer was when some person began to create the LineGraphic. It is not necessarily the Point in the line closest to 0,0.



341
342
343
# File 'lib/graffle/stereotypes.rb', line 341

def origin
  Point.new(self['Points'][0])
end

#pointsObject

An array of Point objects that make up the line. Not editable (yet).



330
331
332
333
334
335
# File 'lib/graffle/stereotypes.rb', line 330

def points
  self['Points'].collect do |p|
    p =~ /\{(.*),\s(.*)\}/
    Point.new(Float($1), Float($2))
  end
end

#toObject Also known as: head

The AbstractGraphic the line goes to.



302
# File 'lib/graffle/stereotypes.rb', line 302

def to; ('Head'); end