Class: Vedeu::Views::Chars Private

Inherits:
Repositories::Collection show all
Defined in:
lib/vedeu/views/chars.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 Cells::Char instances.

Class Method Summary collapse

Constructor Details

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

Class Method Details

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

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:

  • collection (void) (defaults to: [])
  • parent (Vedeu::Views::Stream) (defaults to: nil)
  • name (NilClass|Symbol|String) (defaults to: nil)

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    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.



18
19
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
# File 'lib/vedeu/views/chars.rb', line 18

def self.coerce(collection = [], parent = nil, name = nil)
  if collection.is_a?(Vedeu::Views::Chars)
    collection

  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::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 collection.is_a?(String)
    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
    fail Vedeu::Error::InvalidSyntax,
         'Cannot coerce for Vedeu::View::Chars, as collection is ' \
         'unrecognised.'

  end
end