Sha256: 77de84ce49dfbf17fb2e8fa2fee835404eeb22b0f4b237105d39bc60a0078f30

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Views

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

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

        elsif collection.is_a?(Vedeu::Views::Streams)
          if collection.empty?
            # @todo Investigate whether this is being used.
          end

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

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

          new(coerced_collection, parent, name)

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

        else
          fail Vedeu::Error::InvalidSyntax,
               'Cannot coerce for Vedeu::View::Lines, as collection ' \
               'unrecognised.'

        end
      end

      alias lines value

    end # Lines

  end # Views

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.8.12 lib/vedeu/views/lines.rb
vedeu-0.8.10 lib/vedeu/views/lines.rb
vedeu-0.8.9 lib/vedeu/views/lines.rb
vedeu-0.8.8 lib/vedeu/views/lines.rb
vedeu-0.8.7 lib/vedeu/views/lines.rb