Class: Docx::ArgumentCombiner

Inherits:
Object
  • Object
show all
Defined in:
lib/docx/argument_combiner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ArgumentCombiner

Returns a new instance of ArgumentCombiner.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/docx/argument_combiner.rb', line 4

def initialize(*args)
  @attributes = {}
  args.flatten!
  # Prefixes the model name or custom prefix. Makes it so we don't having naming clashes when used with records from multiple m
  args.each do |arg|
    if arg.is_a?(Hash) && arg.has_key?(:data) && arg.has_key?(:prefix)
      template_attributes = (arg[:data].respond_to?(:template_attributes) && :template_attributes) || :attributes
      arg[:data].send(template_attributes).each_key do |key|
        @attributes["#{arg[:prefix]}_#{key.to_s}".to_sym] = arg[:data].send(template_attributes)[key]
      end
    elsif arg.is_a?(Hash)
      @attributes.merge!(arg)
    else
      template_attributes = (arg.respond_to?(:template_attributes) && :template_attributes) || :attributes
      arg.send(template_attributes).each_key do |key|
        @attributes["#{arg.class.name.underscore}_#{key.to_s}".to_sym] = arg.send(template_attributes)[key]
      end
    end
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/docx/argument_combiner.rb', line 3

def attributes
  @attributes
end