lib/vedeu/views/streams.rb in vedeu-0.8.13 vs lib/vedeu/views/streams.rb in vedeu-0.8.14

- old
+ new

@@ -8,52 +8,58 @@ # # @api private # class Streams < Vedeu::Repositories::Collection - # @param (see Vedeu::Repositories::Collection#initialize) - # @macro raise_invalid_syntax - # @return [Vedeu::Views::Streams] - def self.coerce(collection = [], parent = nil, name = nil) - if collection.is_a?(Vedeu::Views::Streams) - collection + class << self - elsif collection.is_a?(Array) - return new(collection, parent, name) if collection.empty? + include Vedeu::Common - coerced_collection = [] - collection.each do |element| - if element.is_a?(Vedeu::Views::Stream) - coerced_collection << element + # @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 element.is_a?(String) - coerced_collection << Vedeu::Views::Stream.new(value: element) + 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 - end - new(coerced_collection, parent, name) + new(coerced_collection, parent, name) - elsif collection.is_a?(Vedeu::Views::Stream) - new([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? + elsif collection.is_a?(Vedeu::Views::Chars) + return new([], parent, name) if collection.empty? - new([Vedeu::Views::Stream.new(value: collection)], parent, name) + new([Vedeu::Views::Stream.new(value: collection)], parent, name) - elsif collection.is_a?(String) - return new([], parent, name) if collection.empty? + elsif string?(collection) + return new([], parent, name) if collection.empty? - new([Vedeu::Views::Stream.new(value: collection)], parent, name) + 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})" + else + raise Vedeu::Error::InvalidSyntax, + 'Cannot coerce for Vedeu::View::Streams, as collection ' \ + "unrecognised. (#{collection.class.name})" + end end - end + + end # Eigenclass alias streams value end # Streams