Module: Graffle::ShapedGraphic

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

Overview

Visible graphics that aren’t lines. (Those are stereotyped LineGraphic.)

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

.for_line(graffle_id) ⇒ Object

:nodoc:



221
222
223
# File 'lib/graffle/stereotypes.rb', line 221

def self.for_line(graffle_id) # :nodoc:
  self['Line'] = { 'ID' => graffle_id }
end

.lineObject

The LineGraphic this ShapedGraphic labels. This method only exists if the object really is a label, so use is_line_label? first.



234
235
236
# File 'lib/graffle/stereotypes.rb', line 234

def self.line
  container.find_by_id(line_id)
end

.line_idObject

The integer ID of the LineGraphic this ShapedGraphic labels. This method only exists if the object really is a label.

BUG: A line can have more than one label.



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

def self.line_id; self['Line']['ID']; end

.takes_on(o) ⇒ Object

:nodoc:



207
208
209
210
211
212
213
# File 'lib/graffle/stereotypes.rb', line 207

def self.takes_on(o) # :nodoc: 
  if AbstractGraphic.takes_on(o, self)
    o.content.behave_like(Text) if o.has_content?
    o.act_as_line_label if o.is_line_label?
    true
  end
end

Instance Method Details

#act_as_line_labelObject

:nodoc:



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/graffle/stereotypes.rb', line 219

def act_as_line_label  # :nodoc:
  
  def self.for_line(graffle_id) # :nodoc:
    self['Line'] = { 'ID' => graffle_id }
  end

  # The integer ID of the LineGraphic this ShapedGraphic labels.
  # This method only exists if the object really is a label.
  #
  # BUG: A line can have more than one label.
  def self.line_id; self['Line']['ID']; end

  # The LineGraphic this ShapedGraphic labels.
  # This method only exists if the object really is a label, so 
  # use is_line_label? first.
  def self.line
    container.find_by_id(line_id)
  end
end

#bounded_by(x, y, width, height) ⇒ Object

:nodoc:



261
262
263
# File 'lib/graffle/stereotypes.rb', line 261

def bounded_by(x, y, width, height) # :nodoc: 
  self << {"Bounds" => "{{#{x}, #{y}}, {#{width}, #{height}}}" }
end

#boundsObject

This object’s bounding box, an OpenStruct with methods x, y, width, and height.



251
252
253
254
255
# File 'lib/graffle/stereotypes.rb', line 251

def bounds
  self['Bounds'] =~ /\{\{(.*),\s(.*)\}, \{(.*),\s(.*)\}\}/
  OpenStruct.new(:x => Float($1), :y => Float($2), 
                     :width => Float($3), :height => Float($4))
end

#contentObject Also known as: contents

The Text within the object. If there is no text, the return value is a null object that responds to as_lines with an empty array.



270
271
272
273
274
275
276
# File 'lib/graffle/stereotypes.rb', line 270

def content
  if has_key?('Text')
    self['Text']
  else
    Text::Null.new
  end
end

#has_content?Boolean

Does this object contain Text? (The kind you put in when you double-click on the object.)

Returns:

  • (Boolean)


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

def has_content?; self.has_key?('Text'); end

#heightObject

The height of this object’s bounding box.



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

def height; bounds.height; end

#originObject

:nodoc:



257
258
259
# File 'lib/graffle/stereotypes.rb', line 257

def origin # :nodoc:
  Point.new(self['Bounds'])
end

#shaped_graphic_content_linesObject

:nodoc: # can be automatically generated



90
91
92
# File 'lib/graphical_tests_for_rails/stereotype-extensions.rb', line 90

def shaped_graphic_content_lines # :nodoc: # can be automatically generated
  content.as_lines
end

#shaped_graphic_note_linesObject

:nodoc: # can be automatically generated



86
87
88
# File 'lib/graphical_tests_for_rails/stereotype-extensions.rb', line 86

def shaped_graphic_note_lines # :nodoc:    # can be automatically generated
  note.as_lines
end

#widthObject

The width of this object’s bounding box.



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

def width; bounds.width; end

#with_content(string) ⇒ Object

:nodoc:



279
280
281
# File 'lib/graffle/stereotypes.rb', line 279

def with_content(string)  # :nodoc:
  self['Text'] = text(string)
end

#xObject

The x coordinate of this object’s bounding box.



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

def x; bounds.x; end

#yObject

The y coordinate of this object’s bounding box.



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

def y; bounds.y; end