Sha256: fb09c72b5a95df8fbf4642ffdd0ddf7cb7eaccd013a4479d23b7f36e65af5ba6

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Vedeu
  class Line
    include Coercions
    include Presentation

    attr_reader :attributes

    # @param attributes [Hash]
    # @param block [Proc]
    # @return [Hash]
    def self.build(attributes = {}, &block)
      new(attributes, &block).attributes
    end

    # @param attributes [Hash]
    # @param block [Proc]
    # @return [Line]
    def initialize(attributes = {}, &block)
      @attributes = defaults.merge!(attributes)

      if block_given?
        @self_before_instance_eval = eval('self', block.binding)

        instance_eval(&block)
      end
    end

    # @return [Array]
    def streams
      @streams ||= Stream.coercer(attributes[:streams])
    end

    # @return [String]
    def to_s
      [ colour, style, streams ].join
    end

    private

    # @api private
    # @return [Hash]
    def defaults
      {
        colour:  {},
        streams: [],
        style:   []
      }
    end

    # @api private
    # @return []
    def method_missing(method, *args, &block)
      @self_before_instance_eval.send(method, *args, &block)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.18 lib/vedeu/models/line.rb