Sha256: 63807b80141ebe29767d9cad8acfb340e3f65c39d6c7282b581d22f5aec9c833

Contents?: true

Size: 622 Bytes

Versions: 8

Compression:

Stored size: 622 Bytes

Contents

# frozen_string_literal: true

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.8.0 lib/comma/extractor.rb
comma-4.7.0 lib/comma/extractor.rb
comma-4.6.0 lib/comma/extractor.rb
comma-4.5.0 lib/comma/extractor.rb
comma-4.4.0 lib/comma/extractor.rb
comma-4.3.2 lib/comma/extractor.rb
comma-4.3.1 lib/comma/extractor.rb
comma-4.3.0 lib/comma/extractor.rb