[cairo-commit] rcairo/src/lib/cairo paper.rb,1.1,1.2

Kouhei Sutou commit at pdx.freedesktop.org
Tue Apr 8 23:24:22 PDT 2008


Committed by: kou

Update of /cvs/cairo/rcairo/src/lib/cairo
In directory kemper:/tmp/cvs-serv21416/src/lib/cairo

Modified Files:
	paper.rb 
Log Message:
* src/lib/cairo/paper.rb, test/test_paper.rb: improve parser.


Index: paper.rb
===================================================================
RCS file: /cvs/cairo/rcairo/src/lib/cairo/paper.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- paper.rb	9 Apr 2008 06:15:42 -0000	1.1
+++ paper.rb	9 Apr 2008 06:28:53 -0000	1.2
@@ -1,6 +1,6 @@
 module Cairo
   class Paper
-    class ParseError < StandardError
+    class ParseError < ArgumentError
     end
 
     class UnknownPaperName < ParseError
@@ -19,17 +19,33 @@
       end
     end
 
+    class UnrecognizedPaperDescription < ParseError
+      attr_reader :description
+      def initialize(description)
+        @description = description
+        super("unrecognized paper description: #{description.inspect}")
+      end
+    end
+
     class << self
-      def parse(paper_description)
+      def parse(paper_description, robust=false)
         case paper_description
+        when Paper
+          return paper_description.dup
         when Symbol
           paper = resolve_constant(paper_description)
-          raise UnknownPaperName.new(paper_description) if paper.nil?
-          paper
+          return paper.dup if paper
+          raise UnknownPaperName.new(paper_description)
         when String
           paper = resolve_constant(paper_description)
           paper ||= parse_size(paper_description.gsub(/#.*\z/, ''))
+          return paper.dup if paper
+        when Array
+          return new(*paper_description)
         end
+
+        raise UnrecognizedPaperDescription.new(paper_description) if robust
+        nil
       end
 
       @@unit_resolvers = []



More information about the cairo-commit mailing list