Module: WireClient::Converter

Included in:
Account, Transaction
Defined in:
lib/wire_client/base/converters.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#convert(*attributes, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/wire_client/base/converters.rb', line 3

def convert(*attributes, options)
  include InstanceMethods

  method_name = "convert_#{options[:to]}"
  unless InstanceMethods.method_defined?(method_name)
    raise ArgumentError, "Converter '#{options[:to]}' does not exist!"
  end

  attributes.each do |attribute|
    define_method "#{attribute}=" do |value|
      instance_variable_set("@#{attribute}", send(method_name, value))
    end
  end
end