Class: Comma::DataExtractor
- Defined in:
- lib/comma/extractors.rb
Instance Method Summary collapse
Methods inherited from Extractor
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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/comma/extractors.rb', line 44 def method_missing(sym, *args, &block) if args.blank? result = block ? yield(@instance.send(sym)) : @instance.send(sym) @results << result.to_s end args.each do |arg| case arg when Hash arg.each do |k, v| if block @results << (@instance.send(sym).nil? ? '' : yield(@instance.send(sym).send(k)).to_s ) else @results << (@instance.send(sym).nil? ? '' : @instance.send(sym).send(k).to_s ) end end when Symbol if block @results << (@instance.send(sym).nil? ? '' : yield(@instance.send(sym).send(arg)).to_s) else @results << ( @instance.send(sym).nil? ? '' : @instance.send(sym).send(arg).to_s ) end when String @results << (block ? yield(@instance.send(sym)) : @instance.send(sym)).to_s else raise "Unknown data symbol #{arg.inspect}" end end end |