Class: Etcher::Transformers::String

Inherits:
Object
  • Object
show all
Defined in:
lib/etcher/transformers/string.rb

Overview

Formats given key using existing and/or ancillary attributes.

Instance Method Summary collapse

Constructor Details

#initialize(key, **ancillary) ⇒ String

Returns a new instance of String.



11
12
13
14
# File 'lib/etcher/transformers/string.rb', line 11

def initialize key, **ancillary
  @key = key
  @ancillary = ancillary
end

Instance Method Details

#call(attributes) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/etcher/transformers/string.rb', line 16

def call attributes
  value = attributes[key]

  return Success attributes unless value

  Success attributes.merge(key => format(value, **attributes, **ancillary))
rescue KeyError => error
  Failure "Unable to transform #{key.inspect}, missing specifier: " \
          "\"#{error.message[/<.+>/]}\"."
end