Sha256: 4fb7c27bb5999c2b212ac036e20a95bddda896293599ebd6c603fbd9045ba9f6

Contents?: true

Size: 619 Bytes

Versions: 8

Compression:

Stored size: 619 Bytes

Contents

# -*- coding: utf-8 -*-

module Comma

  class Extractor

    def initialize(instance, style, formats)
      @instance = instance
      @style = style
      @formats = formats
      @results = []
    end

    def results
      instance_eval &@formats[@style]
      @results.map { |r| convert_to_data_value(r) }
    end

    def id(*args, &block)
      method_missing(:id, *args, &block)
    end

    def __use__(style)
      # TODO: prevent infinite recursion
      instance_eval(&@formats[style])
    end

    private

    def convert_to_data_value(result)
      result.nil? ? result : result.to_s
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
comma-4.1.0 lib/comma/extractor.rb
comma-4.0.1 lib/comma/extractor.rb
comma-4.0.0 lib/comma/extractor.rb
comma-3.2.4 lib/comma/extractor.rb
comma-3.2.3 lib/comma/extractor.rb
comma-3.2.2 lib/comma/extractor.rb
comma-3.2.1 lib/comma/extractor.rb
comma-3.2.0 lib/comma/extractor.rb