Class: Vedeu::Views::Streams Private

Inherits:
Repositories::Collection show all
Extended by:
Common
Defined in:
lib/vedeu/views/streams.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A collection of Stream instances.

API:

  • private

Instance Attribute Summary

Attributes inherited from Repositories::Collection

#collection, #name, #parent

Class Method Summary collapse

Methods included from Common

absent?, array?, boolean, boolean?, empty_value?, escape?, falsy?, hash?, line_model?, numeric?, positionable?, present?, snake_case, stream_model?, string?, symbol?, truthy?, view_model?

Methods inherited from Repositories::Collection

#add, #initialize, #klass, #to_s

Methods included from Repositories::Assemblage

#[], #any?, #each, #empty?, #eql?, #size

Constructor Details

This class inherits a constructor from Vedeu::Repositories::Collection

Class Method Details

.coerce(collection = [], parent = nil, name = nil) ⇒ Vedeu::Views::Streams

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • (defaults to: [])
  • (defaults to: nil)
  • (defaults to: nil)

    The name of the model or target model to act upon. May default to Vedeu.focus.

Returns:

Raises:

  • When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.

API:

  • private



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vedeu/views/streams.rb', line 20

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