Sha256: 92a810c7fff2f610117b5662a01a2cefd5f0b4d1d41aef111abcf3ae7b019366
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
# frozen_string_literal: true module Vedeu module Views # A collection of {Vedeu::Views::Stream} instances. # # @api private # class Streams < Vedeu::Repositories::Collection # @param (see Vedeu::Repositories::Collection#initialize) # @raise [Vedeu::Error::InvalidSyntax] When the collection # cannot be coerced since it is unrecognised or unsupported. # @return [Vedeu::Views::Streams] def self.coerce(collection = [], parent = nil, name = nil) if collection.is_a?(Vedeu::Views::Streams) collection elsif collection.is_a?(Array) 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 element.is_a?(String) 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 collection.is_a?(String) return new([], parent, name) if collection.empty? new([Vedeu::Views::Stream.new(value: collection)], parent, name) else fail Vedeu::Error::InvalidSyntax, 'Cannot coerce for Vedeu::View::Streams, as collection ' \ "unrecognised. (#{collection.class.name})" end end alias_method :streams, :value end # Streams end # Views end # Vedeu
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.8.5 | lib/vedeu/views/streams.rb |
vedeu-0.8.4 | lib/vedeu/views/streams.rb |