class UIC::MetaData

encoding: utf-8

Constants

HIER

Attributes

by_name[R]

Public Class Methods

inspect() click to toggle source
# File lib/ruic/assets.rb, line 339
def self.inspect
        @name
end
new(xml) click to toggle source
# File lib/ruic/assets.rb, line 273
def initialize(xml)
        @by_name = {'AssetBase'=>AssetBase}

        doc = Nokogiri.XML(xml)
        hack_in_slide_names!(doc)

        HIER.each do |class_name,parent_class_name|
                parent_class = @by_name[parent_class_name]
                el = doc.root.at(class_name)
                @by_name[class_name] = create_class(el,parent_class,el.name)
        end

        # Extend well-known classes with script interfaces after they are created
        @by_name['State'] = @by_name['Slide']
        @by_name['Slide'].instance_eval do
                attr_accessor :index, :name
                define_method :inspect do
                        "<slide ##{index} of #{@el['component'] || @el.parent['component']}>"
                end
                define_method(:slide?){ true }
        end

        refmat = @by_name['ReferencedMaterial']
        @by_name['MaterialBase'].instance_eval do
                define_method :replace_with_referenced_material do
                        type=='ReferencedMaterial' ? self : presentation.replace_asset( self, 'ReferencedMaterial', name:name )
                end
        end

        @by_name['Path'].instance_eval do
                define_method(:anchors){ find _type:'PathAnchorPoint' }
        end

end

Public Instance Methods

create_class(el,parent_class,name,new_defaults={}) click to toggle source

Creates a class from MetaData.xml with accessors for the <Property> listed. Instances of the class are associated with a presentation and know how to get/set values in that XML based on value types, slides, defaults. Also used to create classes from effects, materials, and behavior preambles. @param el [Nokogiri::XML::Element] the element in MetaData.xml representing this class. @param parent_class [Class] the asset class to inherit from. @param name [String] the name of this class. @param new_defaults [Hash] hash mapping attribute name to a custom default value (as string) for this class.

# File lib/ruic/assets.rb, line 316
def create_class(el,parent_class,name,new_defaults={})
        Class.new(parent_class) do
                @name = name.to_s
                @properties = Hash[ el.css("Property").map do |e|
                        type = e['type'] || (e['list'] ? 'String' : 'Float')
                        type = "Float" if type=="float"
                        property = begin
                                UIC::Property.const_get(type).new(e)
                        rescue NameError
                                warn "WARNING: Unsupported property type '#{type}' on\n#{e}\nTreating this as a String."
                                UIC::Property::String.new(e)
                        end
                        new_defaults.delete(property.name)
                        [ property.name, property ]
                end ]

                new_defaults.each do |name,value|
                        if prop=properties[name] # look in ancestor classes
                                @properties[name] = prop.dup
                                @properties[name].default = value
                        end
                end

                def self.inspect
                        @name
                end
        end
end
hack_in_slide_names!(doc) click to toggle source
# File lib/ruic/assets.rb, line 350
def hack_in_slide_names!(doc)
        doc.at('Slide') << '<Property name="name" formalName="Name" type="String" default="Slide" hidden="True" />'
end
new_instance(presentation,el) click to toggle source
# File lib/ruic/assets.rb, line 345
def new_instance(presentation,el)
        klass = @by_name[el.name] || create_class(el,@by_name['Asset'],el.name)
        klass.new(presentation,el)
end