Class: Realize::Value::Resolve

Inherits:
Object
  • Object
show all
Defined in:
lib/realize/value/resolve.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:) ⇒ Resolve

Returns a new instance of Resolve.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/realize/value/resolve.rb', line 19

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

  @key = key

  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



17
18
19
# File 'lib/realize/value/resolve.rb', line 17

def key
  @key
end

Instance Method Details

#transform(resolver, value, _time, _record) ⇒ Object



27
28
29
30
31
# File 'lib/realize/value/resolve.rb', line 27

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

  resolver.get(record, key)
end