Sha256: 708a44b13717ecb157e3d30b3272c8e617a4c556b8810477db2000639584de26

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'vedeu/dsl/composition'
require 'vedeu/models/collection'
require 'vedeu/presentation/presentation'
require 'vedeu/support/common'

require 'vedeu/models/view/interfaces'
require 'vedeu/models/view/interface'

module Vedeu

  # A composition is a collection of interfaces.
  #
  # @api private
  class Composition

    include Vedeu::Presentation
    include Vedeu::Model

    collection Vedeu::Interfaces
    member     Vedeu::Interface

    attr_reader  :interfaces
    alias_method :value, :interfaces

    # Returns a new instance of Composition.
    #
    # @param attributes [Hash]
    # @option attributes colour []
    # @option attributes interfaces []
    # @option attributes style []
    # @return [Composition]
    def initialize(attributes = {})
      @attributes = defaults.merge(attributes)
      @interfaces = @attributes[:interfaces]
      @colour     = Colour.coerce(@attributes[:colour])
      @style      = Style.coerce(@attributes[:style])
    end

    # @param child [Vedeu::Interface]
    # @return []
    def add(child)
      @interfaces = interfaces.add(child)
    end

    # Returns log friendly output.
    #
    # @return [String]
    def inspect
      "<#{self.class.name} (interfaces:#{interfaces.size})>"
    end

    # @return [Vedeu::Interfaces]
    def interfaces
      collection.coerce(@interfaces, self)
    end

    private

    # The default values for a new instance of this class.
    #
    # @return [Hash]
    def defaults
      {
        client:     nil,
        colour:     nil,
        interfaces: [],
        style:      nil,
      }
    end

  end # Composition

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.3.4 lib/vedeu/models/view/composition.rb
vedeu-0.3.3 lib/vedeu/models/view/composition.rb