Sha256: 455899cdbc902d8b890e2f676ab5b205c053de86dc4cf7e568aa3c55342429ea

Contents?: true

Size: 691 Bytes

Versions: 11

Compression:

Stored size: 691 Bytes

Contents

# frozen_string_literal: true

module Realize
  class Value
    # Basic transformer that can take an object and extract a value based off the transformer's
    # key.  If the value passed in is an array then it will select the first record.
    class Resolve
      acts_as_hashable

      attr_reader :key

      def initialize(key:)
        raise ArgumentError, 'key is required' if key.to_s.empty?

        @key = key

        freeze
      end

      def transform(resolver, value, _time, _record)
        record = first(value)

        resolver.get(record, key)
      end

      private

      def first(value)
        value.is_a?(Array) ? value.first : value
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
realize-1.3.0 lib/realize/value/resolve.rb
realize-1.2.0 lib/realize/value/resolve.rb
realize-1.2.0.pre.alpha lib/realize/value/resolve.rb
realize-1.1.1 lib/realize/value/resolve.rb
realize-1.1.1.pre.alpha lib/realize/value/resolve.rb
realize-1.1.0 lib/realize/value/resolve.rb
realize-1.0.0 lib/realize/value/resolve.rb
realize-1.0.0.pre.alpha.3 lib/realize/value/resolve.rb
realize-1.0.0.pre.alpha.2 lib/realize/value/resolve.rb
realize-1.0.0.pre.alpha.1 lib/realize/value/resolve.rb
realize-1.0.0.pre.alpha lib/realize/value/resolve.rb