Split a font's filename and its alias.
[redact.git] / lib / redact / redact.rb
index 59740f70f2f1e23b1477de9c3f6aec0b2cf102dc..7b9a802461c644048235570b3a8482df409f505d 100644 (file)
@@ -1,5 +1,5 @@
 #--
-# $Id: redact.rb 1 2005-03-26 01:32:38Z tilman $
+# $Id: redact.rb 48 2005-06-08 21:38:34Z tilman $
 #
 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
 #
@@ -27,7 +27,7 @@ require "imlib2"
 require "redact/part"
 require "redact/program"
 
-class Object
+class Object # :nodoc:
        undef :id
 end
 
@@ -57,7 +57,7 @@ class String
 end
 
 module Redact
-       VERSION = "0.0.1"
+       VERSION = "0.1.1"
 
        class RedactError < StandardError; end
 
@@ -84,12 +84,13 @@ module Redact
                        @data = DataHash.new
                end
 
-               def collection(name)
+               def collection(name) # :yields: collection
                        c = @collections[name]
 
                        block_given? ? (yield c) : c
                end
 
+               protected
                def to_eet_name
                        "Edje_File"
                end
@@ -105,7 +106,7 @@ module Redact
                end
        end
 
-       class DataHash < Hash
+       class DataHash < Hash # :nodoc:
                def [](key)
                        super.value
                end
@@ -115,7 +116,7 @@ module Redact
                end
        end
 
-       class HashEntry
+       class HashEntry # :nodoc:
                attr_reader :key, :value
 
                def initialize(key, value)
@@ -123,12 +124,14 @@ module Redact
                        @value = value.to_str.dup.freeze
                end
 
+               protected
                def to_eet_name
                        "Edje_Data"
                end
        end
 
-       class FontDirectory < Array
+       class FontDirectory < Array # :nodoc:
+               protected
                def to_eet_name
                        "Edje_Font_Directory"
                end
@@ -138,29 +141,33 @@ module Redact
                end
        end
 
-       class FontDirectoryEntry
-               attr_reader :filename
+       class FontDirectoryEntry # :nodoc:
+               attr_reader :filename, :alias
 
                def initialize(filename)
                        @filename = filename.to_str.dup.freeze
+                       @alias = "Edje." + File.basename(@filename).
+                                sub(/.[^.]+$/, "").freeze
                end
 
+               protected
                def to_eet_name
                        "Edje_Font_Directory_Entry"
                end
 
                def to_eet_properties
-                       {"entry" => [@filename]}
+                       {"entry" => [@alias]}
                end
        end
 
-       class ImageDirectory < Array
+       class ImageDirectory < Array # :nodoc:
                def <<(entry)
                        super
 
                        entry.id = size - 1
                end
 
+               protected
                def to_eet_name
                        "Edje_Image_Directory"
                end
@@ -170,7 +177,7 @@ module Redact
                end
        end
 
-       class ImageDirectoryEntry
+       class ImageDirectoryEntry # :nodoc:
                attr_reader :filename, :image, :id
 
                def initialize(filename)
@@ -191,6 +198,7 @@ module Redact
                        end
                end
 
+               protected
                def to_eet_name
                        "Edje_Image_Directory_Entry"
                end
@@ -203,7 +211,8 @@ module Redact
                end
        end
 
-       class CollectionDirectory < Array
+       class CollectionDirectory < Array # :nodoc:
+               protected
                def to_eet_name
                        "Edje_Part_Collection_Directory"
                end
@@ -213,12 +222,13 @@ module Redact
                end
        end
 
-       class CollectionDirectoryEntry
+       class CollectionDirectoryEntry # :nodoc:
                def initialize(col)
                        @name = col.name.to_str.dup.freeze
                        @id = col.id
                end
 
+               protected
                def to_eet_name
                        "Edje_Part_Collection_Directory_Entry"
                end
@@ -230,8 +240,8 @@ module Redact
        end
 
        class Collection
-               attr_reader :name, :id, :data, :min, :max, :parts, :programs
-               attr_accessor :script
+               attr_reader :name, :id, :data, :min, :max, :parts, :programs,
+                           :script
 
                def initialize(name, id)
                        @name = name.to_str.dup.freeze
@@ -247,7 +257,11 @@ module Redact
                        @script = nil
                end
 
-               def part(name, type = :invalid)
+               def script=(v)
+                       @script = v.to_str.dup
+               end
+
+               def part(name, type = :invalid) # :yields: part
                        p = @parts[name]
                        if p.nil?
                                klass = case type
@@ -261,7 +275,7 @@ module Redact
                                        ImagePart
                                else
                                        raise(ArgumentError,
-                                             "invalid program type - #{type.to_s}")
+                                             "invalid part type - #{type.to_s}")
                                end
 
                                p = klass.new(self, @parts.size, name)
@@ -271,7 +285,7 @@ module Redact
                        block_given? ? (yield p) : p
                end
 
-               def program(name, type = :invalid)
+               def program(name, type = :invalid) # :yields: program
                        p = @programs[name]
                        if p.nil?
                                klass = case type
@@ -322,6 +336,7 @@ module Redact
                        end
                end
 
+               protected
                def to_eet_name
                        "Edje_Part_Collection"
                end