Sha256: 8d51a1eeb1c28da798d700b3b81c27969a92e308c1f363841120b46f1886c264

Contents?: true

Size: 1.78 KB

Versions: 19

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Views

    # A collection of {Vedeu::Views::Stream} instances.
    #
    # @api private
    #
    class Streams < Vedeu::Repositories::Collection

      class << self

        include Vedeu::Common

        # @param (see Vedeu::Repositories::Collection#initialize)
        # @macro raise_invalid_syntax
        # @return [Vedeu::Views::Streams]
        def coerce(collection = [], parent = nil, name = nil)
          if collection.is_a?(Vedeu::Views::Streams)
            collection

          elsif array?(collection)
            return new(collection, parent, name) if collection.empty?

            coerced_collection = []
            collection.each do |element|
              if element.is_a?(Vedeu::Views::Stream)
                coerced_collection << element

              elsif string?(element)
                coerced_collection << Vedeu::Views::Stream.new(value: element)

              end
            end

            new(coerced_collection, parent, name)

          elsif collection.is_a?(Vedeu::Views::Stream)
            new([collection], parent, name)

          elsif collection.is_a?(Vedeu::Views::Chars)
            return new([], parent, name) if collection.empty?

            new([Vedeu::Views::Stream.new(value: collection)], parent, name)

          elsif string?(collection)
            return new([], parent, name) if collection.empty?

            new([Vedeu::Views::Stream.new(value: collection)], parent, name)

          else
            raise Vedeu::Error::InvalidSyntax,
                  'Cannot coerce for Vedeu::View::Streams, as collection ' \
                  "unrecognised. (#{collection.class.name})"

          end
        end

      end # Eigenclass

      alias streams value

    end # Streams

  end # Views

end # Vedeu

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/views/streams.rb
vedeu-0.8.31 lib/vedeu/views/streams.rb
vedeu-0.8.30 lib/vedeu/views/streams.rb
vedeu-0.8.29 lib/vedeu/views/streams.rb
vedeu-0.8.28 lib/vedeu/views/streams.rb
vedeu-0.8.27 lib/vedeu/views/streams.rb
vedeu-0.8.26 lib/vedeu/views/streams.rb
vedeu-0.8.25 lib/vedeu/views/streams.rb
vedeu-0.8.24 lib/vedeu/views/streams.rb
vedeu-0.8.23 lib/vedeu/views/streams.rb
vedeu-0.8.22 lib/vedeu/views/streams.rb
vedeu-0.8.21 lib/vedeu/views/streams.rb
vedeu-0.8.20 lib/vedeu/views/streams.rb
vedeu-0.8.19 lib/vedeu/views/streams.rb
vedeu-0.8.18 lib/vedeu/views/streams.rb
vedeu-0.8.17 lib/vedeu/views/streams.rb
vedeu-0.8.16 lib/vedeu/views/streams.rb
vedeu-0.8.15 lib/vedeu/views/streams.rb
vedeu-0.8.14 lib/vedeu/views/streams.rb