Sha256: edbae93f5044532599adbe24fef4c1dec6f6415b2c01b06d757bbeee8e5ebe56

Contents?: true

Size: 1.74 KB

Versions: 17

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Views

    # A collection of {Vedeu::Cells::Char} instances.
    #
    # @api private
    #
    class Chars < Vedeu::Repositories::Collection

      class << self

        include Vedeu::Common

        # @param collection [void]
        # @param parent [Vedeu::Views::Stream]
        # @macro param_name
        # @macro raise_invalid_syntax
        # @return [Vedeu::Views::Chars]
        def coerce(collection = [], parent = nil, name = nil)
          if collection.is_a?(Vedeu::Views::Chars)
            collection

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

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

            new(coerced_collection, parent, name)

          elsif collection.is_a?(Vedeu::Views::Stream)
            Vedeu::Views::Chars.coerce(collection.value,
                                       collection.parent,
                                       collection.name)

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

            if parent && parent.attributes
              new_collection = Vedeu::DSL::Text.new(collection,
                                                    parent.attributes).chars

              new(new_collection, parent, name)
            end

          else
            raise Vedeu::Error::InvalidSyntax,
                  'Cannot coerce for Vedeu::View::Chars, as collection is ' \
                  'unrecognised.'

          end
        end

      end # Eigenclass

      alias chars value

    end # Chars

  end # Views

end # Vedeu

Version data entries

17 entries across 17 versions & 1 rubygems

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