Module: Builderable::ClassMethods

Defined in:
lib/qif/transaction/builderable.rb

Instance Method Summary collapse

Instance Method Details

#builder_options(options) ⇒ Object



7
8
9
# File 'lib/qif/transaction/builderable.rb', line 7

def builder_options(options)
  @options = options
end

#set_builder_method(attribute, massager = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/qif/transaction/builderable.rb', line 11

def set_builder_method(attribute, massager = nil)
  options = @options || {}
  method_name = ["set", options[:prefix], attribute].compact.join("_")

  define_method(method_name) do |new_value|
    @_builder_values ||= {}

    unless massager.nil?
      if massager.kind_of?(Symbol)
        new_value = self.send(massager, new_value)
      else
        new_value = massager.call(new_value)
      end
    end

    @_builder_values[attribute] = new_value
    self
  end
end