Sha256: 82291ff8c01fe96f747065ac6f1e929c3128e4effe0cc170493581ac6b56bd6a

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

module Transcriber
  class Resource
    module Parser
      def parse(input, options = {})
        prepare_entries(input, options).collect &method(:parse_item)
      end

      private

      def prepare_entries(input, options)
        path = InputPath.resolve(options, Transcriber.configuration.convert_input_keys)
        Array.wrap digg(input, path)
      end

      def parse_item(item)
        self.new.tap do |resource|
          keys.each do |key|
            value = digg(item, key.input_path)
            resource.__send__("#{key.name}=", key.parse(value, resource)) if key.present?(resource)
          end
        end
      end

      def digg(input, path)
        path.inject(input) {|buffer, key| buffer = buffer[key]}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
transcriber-0.0.3 lib/transcriber/resource/parser.rb