class UIC::MetaData::AssetBase

The base class for all assets. All other classes are dynamically created when a `MetaData.xml` file is loaded.

Attributes

name[R]

@return [String] The scene graph name of the asset.

el[RW]

@return [Nokogiri::XML::Element] the internal XML element in the scene graph of the presentation.

presentation[RW]

@return [Presentation] the presentation that this asset is part of.

Public Class Methods

inspect() click to toggle source

@private

# File lib/ruic/assets.rb, line 19
def inspect
        "<#{@name}>"
end
new( presentation, element ) click to toggle source

Create a new asset. This is called for you automatically; you likely should not be using it. @param presentation [Presentation] the presentation owning this asset. @param element [Nokogiri::XML::Element] the internal XML element in the scene graph of the presentation.

# File lib/ruic/assets.rb, line 59
def initialize( presentation, element )
        @presentation = presentation
        @el = element
end
properties() click to toggle source

@return [Hash] a hash mapping attribute names to {Property} instances.

# File lib/ruic/assets.rb, line 14
def properties
        (ancestors[1].respond_to?(:properties) ? ancestors[1].properties : {}).merge(@properties)
end

Public Instance Methods

/(sub_path)
Alias for: at
==(other) click to toggle source

@private no need to document this

# File lib/ruic/assets.rb, line 258
def ==(other)
        (self.class==other.class) && (el==other.el)
end
Also aliased as: eql?
[](attribute_name, slide_name_or_index=nil) click to toggle source

Get the value(s) of an attribute. If `slide_name_or_index` is omitted, creates a ValuesPerSlide proxy for the specified attribute. @example

logo = app/"main:Scene.UI.Logo"
show logo.master?               #=> true  (it's a master object)
show logo['endtime'].linked?    #=> false (the endtime property is unlinked)
show logo['endtime'].values     #=> [10000,500,1000,750]
show logo['endtime',0]          #=> 10000 (the master slide value)
show logo['endtime',"Slide 1"]  #=> 500
show logo['endtime',2]          #=> 1000

@param attribute_name [String,Symbol] the name of the attribute. @param slide_name_or_index [Integer,String] the slide number or name to find the value on. @return [Object] the value of the property on the given slide. @return [ValuesPerSlide] if no slide is specified. @see on_slide @see Presentation#get_attribute

# File lib/ruic/assets.rb, line 211
def [](attribute_name, slide_name_or_index=nil)
        if property = properties[attribute_name.to_s]
                if slide_name_or_index
                        property.get( self, slide_name_or_index ) if has_slide?(slide_name_or_index)
                else
                        UIC::ValuesPerSlide.new(@presentation,self,property)
                end
        end
end
[]=( attribute_name, slide_name_or_index=nil, new_value ) click to toggle source

Set the value of an attribute, either across all slides, or on a particular slide.

@example

logo = app/"main:Scene.UI.Logo"
show logo.master?               #=> true  (it's a master object)
show logo['endtime'].linked?    #=> false (the endtime property is unlinked)
show logo['endtime'].values     #=> [10000,500,1000,750]

logo['endtime',1] = 99
show logo['endtime'].values     #=> [10000,99,1000,750]

logo['endtime'] = 42
show logo['endtime'].values     #=> [42,42,42,42]
show logo['endtime'].linked?    #=> false (the endtime property is still unlinked)

@param attribute_name [String,Symbol] the name of the attribute. @param slide_name_or_index [Integer,String] the slide number or name to set the value on. @param new_value [Numeric,String] the new value for the attribute. @see Presentation#set_attribute

# File lib/ruic/assets.rb, line 240
def []=( attribute_name, slide_name_or_index=nil, new_value )
        if property = properties[attribute_name.to_s] then
                property.set(self,new_value,slide_name_or_index)
        end
end
at(sub_path) click to toggle source

Find an asset by relative scripting path.

@example

preso = app.main
layer = preso/"Scene.Layer"
cam1  = app/"main:Scene.Layer.Camera"
cam2  = preso/"Scene.Layer.Camera"
cam3  = layer/"Camera"
cam4  = cam1/"parent.Camera"

assert cam1==cam2 && cam2==cam3 && cam3==cam4

@return [MetaData::AssetBase] The found asset, or `nil` if it cannot be found.

@see Application#at @see Presentation#at

# File lib/ruic/assets.rb, line 45
def at(sub_path)
        presentation.at(sub_path,@el)
end
Also aliased as: /
children() click to toggle source

@return [Array<AssetBase>] array of child assets in the scene graph. Children are in scene graph order. @see Presentation#child_assets

# File lib/ruic/assets.rb, line 77
def children
        presentation.child_assets(self)
end
component() click to toggle source

@return [AssetBase] the component or scene that owns this asset.

If this asset is a component, does not return itself.

@see Presentation#owning_component

# File lib/ruic/assets.rb, line 109
def component
        presentation.owning_component(self)
end
component?() click to toggle source

@return [Boolean] `true` if this asset is a component or Scene.

# File lib/ruic/assets.rb, line 114
def component?
        @el.name=='Component' || @el.name=='Scene'
end
eql?(other)
Alias for: ==
find(criteria={},&block) click to toggle source

Find descendant assets matching criteria. This method is the same as (but more convenient than) {Presentation#find} using the `:_under` criteria. See that method for documentation of the `criteria`.

@example

preso = app.main
group = preso/"Scene.Layer.Vehicle"
tires = group.find name:/^Tire/

# alternative
tires = preso.find name:/^Tire/, _under:group

@return [Array<AssetBase>]

@see Presentation#find

# File lib/ruic/assets.rb, line 101
def find(criteria={},&block)
        criteria[:_under] ||= self
        presentation.find(criteria,&block)
end
has_slide?(slide_name_or_index) click to toggle source

@param slide_name_or_index [Integer,String] the slide number of name to check for presence on. @return [Boolean] `true` if this asset is present on the specified slide. @see Presentation#has_slide?

# File lib/ruic/assets.rb, line 132
def has_slide?(slide_name_or_index)
        presentation.has_slide?(self,slide_name_or_index)
end
hierarchy() click to toggle source

@return [String] the hierarchy under the element (for debugging purposes).

# File lib/ruic/assets.rb, line 82
def hierarchy
        presentation.hierarchy(self)
end
inspect()
Alias for: to_s
master?() click to toggle source

@return [Boolean] `true` if this asset is on the master slide. @see Presentation#master?

# File lib/ruic/assets.rb, line 120
def master?
        presentation.master?(self)
end
name() click to toggle source

@return [String] the name of this asset in the scene graph.

# File lib/ruic/assets.rb, line 182
def name
        properties['name'] ? properties['name'].get( self, presentation.slide_index(self) ) : type
end
name=( new_name ) click to toggle source

Change the name of the asset in the scene graph. @param new_name [String] the new name for this asset. @return [String] the new name.

# File lib/ruic/assets.rb, line 189
def name=( new_name )
        @path = nil # invalidate the memoization
        properties['name'].set( self, new_name, presentation.slide_index(self) )
end
on_slide(slide_name_or_index) click to toggle source

@example

logo = app/"main:Scene.UI.Logo"
assert logo.master?             # It's a master object

show logo['endtime'].values     #=> [10000,500,1000,750]
show logo['opacity'].values     #=> [100,0,0,100]
logo1 = logo.on_slide(1)
logo2 = logo.on_slide(2)
show logo1['endtime']           #=> 500
show logo2['endtime']           #=> 1000
show logo1['opacity']           #=> 0
show logo2['opacity']           #=> 0

logo2['opacity'] = 66
show logo['opacity'].values     #=> [100,0,66,100]

@param slide_name_or_index [Integer,String] the slide number or name to create the proxy for. @return [SlideValues] a proxy that yields attribute values for a specific slide.

# File lib/ruic/assets.rb, line 160
def on_slide(slide_name_or_index)
        if has_slide?(slide_name_or_index)
                UIC::SlideValues.new( self, slide_name_or_index )
        end
end
parent() click to toggle source

@return [AssetBase] the parent of this asset in the scene graph. @see Presentation#parent_asset

# File lib/ruic/assets.rb, line 71
def parent
        presentation.parent_asset(self)
end
path() click to toggle source

@return [String] the script path to this asset. @see path_to @see Presentation#path_to

# File lib/ruic/assets.rb, line 169
def path
        @path ||= @presentation.path_to(self)
end
path_to(other_asset) click to toggle source

@param other_asset [AssetBase] the asset to find the relative path to. @return [String] the script path to another asset, relative to this one. @see path @see Presentation#path_to

# File lib/ruic/assets.rb, line 177
def path_to(other_asset)
        @presentation.path_to(other_asset,self)
end
properties() click to toggle source

@return [Hash] a hash mapping attribute names to {Property} instances.

# File lib/ruic/assets.rb, line 25
def properties
        self.class.properties
end
slide?() click to toggle source

@return [Boolean] `true` if this asset is a Slide.

# File lib/ruic/assets.rb, line 125
def slide?
        false
end
slides() click to toggle source

@return [SlideCollection] an array-like collection of all slides that the asset is available on. @see Presentation#slides_for

# File lib/ruic/assets.rb, line 138
def slides
        presentation.slides_for(self)
end
to_s() click to toggle source

@private no need to document this

# File lib/ruic/assets.rb, line 252
def to_s
        "<#{type} #{path}>"
end
Also aliased as: inspect
to_xml() click to toggle source

@return [String] the XML representation of the scene graph element.

# File lib/ruic/assets.rb, line 247
def to_xml
        @el.to_xml
end
type() click to toggle source

@return [String] the type of this asset. For example: `“Model”`, `“Material”`, `“ReferencedMaterial”`, `“PathAnchorPoint”`, etc.

# File lib/ruic/assets.rb, line 65
def type
        self.class.name
end