Code cleanup.
[redact.git] / lib / redact / part.rb
index 4d6cf9f5e410f230580bb7c40cec08c1dea2b71d..f915a4b5edf1ba2f2139f66d63c13c18c4e4149c 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: part.rb 19 2005-04-02 22:05:24Z tilman $
+# $Id: part.rb 22 2005-04-02 22:29:50Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -58,12 +58,10 @@ module Redact
                end
 
                def clip=(part)
-                       if self == part
+                       if part == self
                                raise(ArgumentError, "cannot clip part to itself")
-                       elsif part.nil?
-                               @clip = nil
-                       elsif part.collection != @collection
-                               raise(ArgumentError, "parts' collections not identical")
+                       elsif !part.nil? && part.collection != @collection
+                               raise(ArgumentError, "items not in the same collection")
                        else
                                @clip = part
                        end
@@ -124,22 +122,13 @@ module Redact
        end
 
        class TextPart < Part
-               EFFECT_NONE = 0
-               EFFECT_PLAIN = 1
-               EFFECT_OUTLINE = 2
-               EFFECT_SOFT_OUTLINE = 3
-               EFFECT_SHADOW = 4
-               EFFECT_SOFT_SHADOW = 5
-               EFFECT_OUTLINE_SHADOW = 6
-               EFFECT_OUTLINE_SOFT_SHADOW = 7
-
                attr_accessor :effect
 
                def initialize(collection, id, name)
                        super
 
                        @type = TYPE_TEXT
-                       @effect = EFFECT_NONE
+                       @effect = :none
                end
 
                protected
@@ -148,7 +137,20 @@ module Redact
                end
 
                def to_eet_properties
-                       super.merge!({"effect" => [@effect, :char]})
+                       effect = case @effect
+                       when :none: 0
+                       when :plain: 1
+                       when :outline: 2
+                       when :soft_outline: 3
+                       when :shadow: 4
+                       when :soft_shadow: 5
+                       when :outline_shadow: 6
+                       when :outline_soft_shadow: 7
+                       else
+                               raise(RedactError, "invalid effect value - #{@effect}")
+                       end
+
+                       super.merge!({"effect" => [effect, :char]})
                end
        end
 
@@ -178,10 +180,10 @@ module Redact
                end
 
                def confine=(part)
-                       if part == self
+                       if part == @part
                                raise(ArgumentError, "cannot confine part to itself")
                        elsif !part.nil? && part.collection != @part.collection
-                               raise(ArgumentError, "parts' collections not identical")
+                               raise(ArgumentError, "items not in the same collection")
                        else
                                @confine = part
                        end
@@ -275,27 +277,21 @@ module Redact
                        pairs.map { |p| p.hex }
                end
 
-               def map_aspect_preference
-                       case @aspect_preference
-                       when :none
-                               0
-                       when :vertical
-                               1
-                       when :horizontal
-                               2
-                       when :both
-                               3
-                       else
-                               raise(RedactError, "invalid aspect preference value - " +
-                                     @aspect_preference.to_s)
-                       end
-               end
-
                def to_eet_name
                        "Edje_Part_Description"
                end
 
                def to_eet_properties
+                       asp_pref = case @aspect_preference
+                       when :none: 0
+                       when :vertical: 1
+                       when :horizontal: 2
+                       when :both: 3
+                       else
+                               raise(RedactError, "invalid aspect preference value - " +
+                                     @aspect_preference.to_s)
+                       end
+
                        {"state.name" => [@name],
                         "state.value" => [@value, :double],
                         "visible" => [@visible],
@@ -309,7 +305,7 @@ module Redact
                         "step.y" => [@step[1]],
                         "aspect.min" => [@aspect[0], :double],
                         "aspect.max" => [@aspect[1], :double],
-                        "aspect.prefer" => [map_aspect_preference, :char],
+                        "aspect.prefer" => [asp_pref, :char],
                         "rel1.relative_x" => [@rel[0].rel[0], :double],
                         "rel1.relative_y" => [@rel[0].rel[1], :double],
                         "rel1.offset_x" => [@rel[0].offset[0]],