Sha256: d82b67e8ed76a91ccec861658117092f1588c898509980722ce1916029c7b394

Contents?: true

Size: 879 Bytes

Versions: 19

Compression:

Stored size: 879 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Coercers

    # Provides the mechanism to convert a value into a
    # {Vedeu::Models::Page}.
    #
    # @api private
    #
    class Page < Vedeu::Coercers::Coercer

      # @macro raise_fatal
      # @return [Vedeu::Models::Page]
      def coerce
        if coerced?
          value

        elsif value.is_a?(Vedeu::Models::Row)
          klass.new([value])

        elsif array?(value) && value.empty?
          klass.new([Vedeu::Models::Row.coerce(value)])

        elsif array?(value) || value.is_a?(Vedeu::Buffers::View)
          values = value.map { |v| Vedeu::Models::Row.coerce(v) }

          klass.new(values)

        else
          incoercible!

        end
      end

      private

      # @return [Class]
      def klass
        Vedeu::Models::Page
      end

    end # Page

  end # Coercers

end # Vedeu

Version data entries

19 entries across 19 versions & 1 rubygems

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