Class: CsvRecord::CsvFields

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/csv_record/csv_fields.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/csv_record/csv_fields.rb', line 34

def method_missing(meth, *args, &block)
  if self.to_a.respond_to? meth
    self.to_a.public_send meth, *args, &block
  else
    super # You *must* call super if you don't handle the
          # method, otherwise you'll mess up Ruby's method
          # lookup.
  end
end

Instance Method Details

#<<(field) ⇒ Object Also known as: add



8
9
10
# File 'lib/csv_record/csv_fields.rb', line 8

def <<(field)
  self.fields << field
end

#each(&block) ⇒ Object



30
31
32
# File 'lib/csv_record/csv_fields.rb', line 30

def each(&block)
  self.fields.each &block
end

#fieldsObject



4
5
6
# File 'lib/csv_record/csv_fields.rb', line 4

def fields
  @fields ||= []
end

#find_with_doppelganger(doppelganger) ⇒ Object



24
25
26
27
28
# File 'lib/csv_record/csv_fields.rb', line 24

def find_with_doppelganger(doppelganger)
  self.fields.select do |field|
    field.is? doppelganger
  end.first
end

#include?(field) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/csv_record/csv_fields.rb', line 12

def include?(field)
  self.has_doppelganger? field
end