Sha256: c00c4237cfd10320e930441849c9f8da7d8d666f1a36ac66dcb040d773409f20

Contents?: true

Size: 925 Bytes

Versions: 3

Compression:

Stored size: 925 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Coercers

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

      # @macro raise_fatal
      # @return [Vedeu::Editor::Lines]
      def coerce
        if coerced?
          klass.new(value.lines)

        elsif value.is_a?(Array)
          collection = value.map do |line|
            Vedeu::Editor::Line.coerce(line)
          end

          klass.new(collection)

        elsif string?(value)
          collection = value.lines.map(&:chomp).map do |line|
            Vedeu::Editor::Line.coerce(line)
          end

          klass.new(collection)

        else
          klass.new

        end
      end

      private

      # @return [Class]
      def klass
        Vedeu::Editor::Lines
      end

    end # EditorLines

  end # Coercers

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

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