Class: CsvBuilder::CsvProxy

Inherits:
FilterProxy show all
Defined in:
lib/csv_builder/csv_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#base, #options, #target

Instance Method Summary collapse

Methods inherited from FilterProxy

#<<

Methods inherited from Proxy

#init

Constructor Details

#initialize(data, options = {}) ⇒ CsvProxy

Returns a new instance of CsvProxy.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/csv_builder/csv_proxy.rb', line 6

def initialize(data, options = {})
  super(data, options).tap do

    init(CSV.new(data, @options), data) do

      @ivar_names = base.instance_variables.select do |ivar|
        CSV::DEFAULT_OPTIONS.keys.map { |key| "@#{key}" }.include?(ivar.to_s)
      end
    end

  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CsvBuilder::Proxy

Instance Method Details

#[](key) ⇒ Object



19
20
21
22
23
# File 'lib/csv_builder/csv_proxy.rb', line 19

def [](key)
  if @ivar_names.include?(ivar_key = "@#{key}".intern)
    base.instance_variable_get(ivar_key)
  end
end

#[]=(key, value) ⇒ Object



25
26
27
28
29
# File 'lib/csv_builder/csv_proxy.rb', line 25

def []=(key, value)
  if @ivar_names.include?(ivar_key = "@#{key}".intern)
    base.instance_variable_set(ivar_key, value)
  end
end

#settingsObject



31
32
33
34
35
36
37
# File 'lib/csv_builder/csv_proxy.rb', line 31

def settings
  @ivar_names.inject({}) do |hash,key|
    hash.tap do
      hash[key.to_s[1..-1].intern] = base.instance_variable_get(key)
    end
  end
end