Class: Comma::DataExtractor

Inherits:
Extractor show all
Defined in:
lib/comma/extractors.rb

Instance Method Summary collapse

Methods inherited from Extractor

#initialize, #results

Constructor Details

This class inherits a constructor from Comma::Extractor

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/comma/extractors.rb', line 41

def method_missing(sym, *args, &block)
  @results << @instance.send(sym).to_s if args.blank?
  
  args.each do |arg|
    case arg
    when Hash
      arg.each do |k, v|
        @results << @instance.send(sym).send(k).to_s
      end
    when Symbol
      @results << @instance.send(sym).send(arg).to_s
    when String
      @results << @instance.send(sym).to_s
    else
      raise "Unknown data symbol #{arg.inspect}"
    end
  end
end