Sha256: a626f38882f7d65182b4d076b3c2439e54841e5c994c5308dc360679db9ebdd0

Contents?: true

Size: 958 Bytes

Versions: 4

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Coercers

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

      # Produces new objects of the correct class from the value,
      # ignores objects that have already been coerced.
      #
      # @return [Vedeu::Presentation::Style]
      def coerce
        if coerced?
          value

        elsif value.is_a?(Hash)
          if present?(value[:style])
            if value[:style].is_a?(klass)
              value[:style]

            else
              Vedeu::Coercers::Style.coerce(value[:style])

            end

          else
            klass.new

          end

        else
          klass.new(value)

        end
      end

      private

      # @return [Class]
      def klass
        Vedeu::Presentation::Style
      end

    end # Style

  end # Coercers

end # Vedeu

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.8.13 lib/vedeu/coercers/style.rb
vedeu-0.8.12 lib/vedeu/coercers/style.rb
vedeu-0.8.10 lib/vedeu/coercers/style.rb
vedeu-0.8.9 lib/vedeu/coercers/style.rb