Module: Graffle

Included in:
GraphicalTestsForRails::GraphicArrayOrderings::InWorkflowOrder
Defined in:
lib/graffle.rb,
lib/graffle/point.rb,
lib/graffle/version.rb,
lib/graffle/stereotypes.rb,
lib/graffle/styled-text-reader.rb,
lib/graphical_tests_for_rails/stereotype-extensions.rb

Overview

Defined Under Namespace

Modules: AbstractGraphic, Builders, Container, Document, Group, LineGraphic, Note, ShapedGraphic, Sheet, Text Classes: Point, StyledTextReader

Constant Summary collapse

Version =
'0.2.0'

Class Method Summary collapse

Class Method Details

.data_from(filename) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/graffle.rb', line 50

def self.data_from(filename)
  possible_gzip_header = File.read(filename, 2)
  if possible_gzip_header.unpack('CC') == [0x1f, 0x8b]
    `gunzip < '#{filename}'`
  else
    File.read(filename)
  end
end

.parse(filename_or_xml) ⇒ Object

Parse the given data and stereotype the result. Returns an object stereotyped as Graffle::Document. Deprecated in favor of Parse.parse_file and Parse.parse_xml.



25
26
27
28
29
30
31
32
33
34
# File 'lib/graffle.rb', line 25

def self.parse(filename_or_xml)
  puts "Graffle.parse is deprecated in favor of Graffle.parse_file or Graffle.parse_xml."
  if File.directory?(filename_or_xml)
    filename_or_xml = File.join(filename_or_xml, "data.plist")
  end

  prog1(Plist.parse_xml(filename_or_xml)) do | doc |
    Document.takes_on(doc)
  end
end

.parse_file(filename) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/graffle.rb', line 36

def self.parse_file(filename)
  if File.directory?(filename)
    filename = File.join(filename, "data.plist")
  end

  parse_xml(data_from(filename))
end

.parse_xml(content) ⇒ Object



44
45
46
47
48
# File 'lib/graffle.rb', line 44

def self.parse_xml(content)
  prog1(Plist.parse_xml(content)) do | doc |
    Document.takes_on(doc)
  end
end

.stereotype(o) ⇒ Object

:nodoc:



59
60
61
62
63
64
65
# File 'lib/graffle.rb', line 59

def self.stereotype(o)        # :nodoc:
  return true if ShapedGraphic.takes_on(o)
  return true if LineGraphic.takes_on(o)
  return true if Group.takes_on(o)
  # Sheet has no distinguishing marks.
  false
end